SSH的登录项目
/**********************1SSH项目配置方法************************/
1) 新建一个javaweb项目。
2)选定当前项目,点击窗体上的Myeclips找到ProjectCapebilities找到点击
Add Struts Capebilities选择struts2.1下面选择/*,点击next下一步
勾选Struts2 Spring Libraries包,然后finish。
3)选定当前项目,点击窗体上的Myeclips找到ProjectCapebilities找到点击
Add Spring Capebilities选择Spring2.5并且点击第四个jar包
Spring2.5Persistence JDBCLibraries包,还有勾选Spring2.5webLibraries包,
下面将add勾去掉选择copy,然后finish。
4)数据库新建一个驱动。
5)选定当前项目,点击窗体上的Myeclips找到ProjectCapebilities找到点击
Add HibernateCapebilities选择Hibernate3.2,下面将add勾去掉选择copy,
下一步选择第二个勾选Spring的那一个,再下一步选择第二个勾选Existing
再下一步将准备好的数据库驱动选上,再下一步,新建一个包名com.hpsvse.entity
然后finish。
/**********************2jar的包的冲突问题************************/
1)点击窗体上的window选择Preferences打开
找到Myeclips选项并且展开找到Project Capebilities找到目录下的Struts2点击打开
在右侧众多jar包中找到antlr-2.7.2.jar在右边remove掉。
antlr-2.7.6的jar包要留下。
2)asm.jar留下,asm-2.2.3.jar
版本去掉,在asm-2.2.3.jar
上右键,找到Build Path右移动找到Remove from Build Path
/**********************3Struts.xml配置详解************************/
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC"-//Apache Software Foundation//DTDStruts Configuration 2.1//EN""http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 将struts2对象交给spring容器管理 -->
<constantname="struts.objectFactory"value="spring"></constant>
<packagename="userInfo"extends="struts-default">
<actionname="userInfo_*"class="userInfoAction"
method="{1}">
<result>/success.jsp</result>
<resultname="input">/login.jsp</result>
</action>
</package>
</struts>
/**********************4applicationContext.xml初始内容************************/
<?xmlversion="1.0"encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beanid="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<propertyname="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<propertyname="url"
value="jdbc:sqlserver://localhost:1433;databaseName=DB">
</property>
<propertyname="username"value="sa"></property>
<propertyname="password"value="svse"></property>
</bean>
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="dataSource">
<refbean="dataSource"/>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
</props>
</property>
</bean></beans>
/**********************5applicationContext.xml项目内容************************/
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<beanid="dataSource"class="org.apache.commons.dbcp.BasicDataSource">
<propertyname="driverClassName"value="com.microsoft.sqlserver.jdbc.SQLServerDriver">
</property>
<propertyname="url"
value="jdbc:sqlserver://localhost:1433;databaseName=DB">
</property>
<propertyname="username"value="sa"></property>
<propertyname="password"value="svse"></property>
</bean>
<beanid="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<propertyname="dataSource">
<refbean="dataSource"/>
</property>
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.format_sql">true</prop>
</props>
</property>
<propertyname="mappingResources">
<list>
<value>com/hpsvse/entity/UserInfo.hbm.xml</value>
</list>
</property>
</bean>
<beanid="userInfoDAO"class="com.hpsvse.dao.impl.UserInfoDAOImpl">
<propertyname="sessionFactory"ref="sessionFactory"></property>
</bean>
<beanid="userInfoService"class="com.hpsvse.service.impl.UserInfoServiceImpl">
<propertyname="userInfoDAO"ref="userInfoDAO"></property>
</bean>
<beanid="userInfoAction"class="com.hpsvse.action.UserInfoAction"scope="prototype">
<propertyname="userInfoService"ref="userInfoService"></property>
</bean>
</beans>
/**********************6web.xml项目内容************************/
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appversion="2.5"xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<!-- spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- struts2的过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
/**********************7hibernate.reveng.xml项目内容************************/
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEhibernate-reverse-engineeringPUBLIC"-//Hibernate/HibernateReverse Engineering DTD 3.0//EN""http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<tablename="userInfo"schema="dbo"catalog="DB">
<primary-key>
<generatorclass="identity"></generator>
</primary-key>
</table>
</hibernate-reverse-engineering>
/**********************8项目整体截图************************/
/**********************9数据库************************/
use master
go
createdatabase DB
go
use DB
go
createTable UserInfo
(
userId intidentityprimarykey,
userName varchar(20)notnull,
userPwd varchar(20)notnull
)
insertinto UserInfo values('admin','123')
select*from UserInfo