一、开发条件:WIN7

1)下载Eclipse最新版http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/SR2/eclipse-jee-galileo-SR2-win32.zip绿色版无需安装直接解压根目录eclipse.exe即可运行。

2)下载Tomcathttp://tomcat.apache.org/download-60.cgi 安装。

3)下载Struts2最新版http://struts.apache.org/download.cgi#struts2181 压缩包解压。

4)下载Spring最新版http://www.springsource.org/download 压缩包解压

5)下载Hibernate最新版http://sourceforge.net/projects/hibernate/files/hibernate3/3.5.1-Final/压缩包解压

二、设置

1)打开Eclipse新建一个DynamicWeb

1)src目录下添加文件struts.xml和hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <package name="default" namespace="/" extends="struts-default">        <action name="Login" class="LoginAction">         <result name="success">/success.jsp</result>         <result name="error">/error.jsp</result>        </action>        <action name="ImageUpload" class="ImageUpload">         <result name="success">/success.jsp</result></action>    </package></struts>

hibernate连接SqlServer2005配置<?xml version='1.0' encoding='utf-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>        <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=test</property>        <property name="connection.username">sa</property>        <property name="connection.password"></property>        <property name="connection.pool_size">1</property>        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>        <property name="current_session_context_class">thread</property>        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>        <property name="show_sql">true</property>        <property name="hbm2ddl.auto">update</property>        <mapping resource="test.hbm.xml"/>    </session-factory></hibernate-configuration>

2)修改WebContent/WEB-INF/下Web.xml增加applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Web</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

3)Copy hibernate解压目录的hibernate3.jar和lib/required目录下的 jar包,到WebContent/WEB-INF/lib目录其余jar包 除sqljdbc.jar和com.springsource.slf4j.jcl-1.5.6.jar外都从struts2 copy过来

commons.io-1.3.2.jar、commons.fileupload.1.2.1.jar是实现文件上传必须的包可以不添加。sqljdbc负责链接SqlServer数据库,无slf4j系统无法运行,看了用log4j可以解决该问题,不过需要配置,麻烦,因此用com.springsource.slf4j.jcl-1.5.6.jar代替。

4)连接SqlServer的问题

到微软下载http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=6d483869-816a-44cb-9787-a866235efc7c sqljdbc压缩包解压, sqljdbc.jar copy到WebContent/WEB-INF/lib

auth 目录的sqljdbc_auth.dll copy到c:/windows/system32目录。 xa目录的sqljdbc_xa.dll copy到SqlServer安装目录90/DTS/Binn  执行xa_install.sql,开启Nativive Client和Sqlserver的TCP/IP连接 重启sqlserver。

posted on 2010-05-03 13:16  风尘仆仆  阅读(906)  评论(1编辑  收藏  举报