eShop电子商城的SSH实现的用户模块(1)登录和注册配置文件和页面关键代码(V...
2010-12-14 12:25
1036 查看
【struts—config.xml】:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="userForm" type="com.eshop.forms.User"></form-bean>
</form-beans>
<global-forwards>
<forward name="error" path="/index.jsp" redirect="true"/>
</global-forwards>
<action-mappings>
<action path="/regist"
type="org.springframework.web.struts.DelegatingActionProxy"
name="userForm"
scope="request"
>
<forward name="success" path="/login.jsp" redirect="true"/>
</action>
<action path="/login"
type="org.springframework.web.struts.DelegatingActionProxy"
name="userForm"
scope="request"
>
<forward name="success" path="/display.jsp" redirect="true"/>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
【web.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"> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
【Spring配置文件】:
1.applicationContext-actions.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean name="/regist" class="com.eshop.actions.AddUserAction">
<property name="userManager" ref="userManage">
</property>
</bean>
<bean name="/login" class="com.eshop.actions.LoginUserAction">
<property name="userManager" ref="userManager"></property>
</bean>
</beans>
2.applicationContext-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="userDao" class="com.eshop.dao.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="userManage" class="com.eshop.managers.UserManagerImpl">
<property name="userDao" ref="userDao"/>
</bean>
</beans>
3.applicationContext-common.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" >
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.eshop.dao.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>
【hibernate.cfg.xml】:
<!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="hibernate.connection.url">jdbc:mysql://localhost:3309/eshop</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/eshop/forms/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
【User.hbm.xml】:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.eshop.forms">
<class name="User" table="t_user">
<id name="id">
<generator class="native"/>
</id>
<property name="username" unique="true" not-null="true"/>
<property name="password" not-null="true"/>
<property name="passwordQuestion"></property>
<property name="passwordAnswer"></property>
<property name="realName" not-null="true" type="string"/>
<property name="telphone"></property>
<property name="address"></property>
<property name="email"/>
<property name="cellPhone"></property>
<property name="postNo"></property>
<property name="idCardNo"/>
</class>
</hibernate-mapping>
【注册页面:index.jsp】:
<form name="" method="post" action="regist.do">
<input type="hidden" name="action" value="regist">
Username:
<input type="text" name="username">
<br>
Password:
<input type="password" name="password">
<br>
realName:
<input type="text" name="realName">
<br>
telphone:
<input type="text" name="telphone">
<br>
address:
<input type="text" name="address">
<br>
email:
<input type="text" name="email">
<br>
cellPhone:
<input type="text" name="cellPhone">
<br>
postNo
<input type="text" name="postNo">
<br>
idCardNo:
<input type="text" name="idCardNo">
<br>
<input type="submit" value="Submit">
</form>
【登录页面:login.jsp】:
<body>
<h1>恭喜注册成功,请登录</h1><hr>
<html:form action="login.do" method="post" focus="login">
<table border="0">
<tr>
<td>Username:</td>
<td><html:text property="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><html:password property="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit/></td>
</tr>
</table>
</html:form>
</body>
</html:html>
为了您的安全,请只打开来源可靠的网址
打开网站 取消
来自: http://hi.baidu.com/cpuhandou/blog/item/70ef04d0331737d5572c8495.html
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="userForm" type="com.eshop.forms.User"></form-bean>
</form-beans>
<global-forwards>
<forward name="error" path="/index.jsp" redirect="true"/>
</global-forwards>
<action-mappings>
<action path="/regist"
type="org.springframework.web.struts.DelegatingActionProxy"
name="userForm"
scope="request"
>
<forward name="success" path="/login.jsp" redirect="true"/>
</action>
<action path="/login"
type="org.springframework.web.struts.DelegatingActionProxy"
name="userForm"
scope="request"
>
<forward name="success" path="/display.jsp" redirect="true"/>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
【web.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"> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>Spring character encoding filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Spring character encoding filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
【Spring配置文件】:
1.applicationContext-actions.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean name="/regist" class="com.eshop.actions.AddUserAction">
<property name="userManager" ref="userManage">
</property>
</bean>
<bean name="/login" class="com.eshop.actions.LoginUserAction">
<property name="userManager" ref="userManager"></property>
</bean>
</beans>
2.applicationContext-beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<bean id="userDao" class="com.eshop.dao.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="userManage" class="com.eshop.managers.UserManagerImpl">
<property name="userDao" ref="userDao"/>
</bean>
</beans>
3.applicationContext-common.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"> <!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" >
<ref bean="sessionFactory" />
</property>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="modify*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 那些类的哪些方法参与事务 -->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.eshop.dao.*.*(..))"/>
<aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>
</aop:config>
</beans>
【hibernate.cfg.xml】:
<!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="hibernate.connection.url">jdbc:mysql://localhost:3309/eshop</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/eshop/forms/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
【User.hbm.xml】:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.eshop.forms">
<class name="User" table="t_user">
<id name="id">
<generator class="native"/>
</id>
<property name="username" unique="true" not-null="true"/>
<property name="password" not-null="true"/>
<property name="passwordQuestion"></property>
<property name="passwordAnswer"></property>
<property name="realName" not-null="true" type="string"/>
<property name="telphone"></property>
<property name="address"></property>
<property name="email"/>
<property name="cellPhone"></property>
<property name="postNo"></property>
<property name="idCardNo"/>
</class>
</hibernate-mapping>
【注册页面:index.jsp】:
<form name="" method="post" action="regist.do">
<input type="hidden" name="action" value="regist">
Username:
<input type="text" name="username">
<br>
Password:
<input type="password" name="password">
<br>
realName:
<input type="text" name="realName">
<br>
telphone:
<input type="text" name="telphone">
<br>
address:
<input type="text" name="address">
<br>
email:
<input type="text" name="email">
<br>
cellPhone:
<input type="text" name="cellPhone">
<br>
postNo
<input type="text" name="postNo">
<br>
idCardNo:
<input type="text" name="idCardNo">
<br>
<input type="submit" value="Submit">
</form>
【登录页面:login.jsp】:
<body>
<h1>恭喜注册成功,请登录</h1><hr>
<html:form action="login.do" method="post" focus="login">
<table border="0">
<tr>
<td>Username:</td>
<td><html:text property="username" /></td>
</tr>
<tr>
<td>Password:</td>
<td><html:password property="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit/></td>
</tr>
</table>
</html:form>
</body>
</html:html>
为了您的安全,请只打开来源可靠的网址
打开网站 取消
来自: http://hi.baidu.com/cpuhandou/blog/item/70ef04d0331737d5572c8495.html
相关文章推荐
- eShop电子商城的SSH实现的用户模块(1)登录和注册Bean(Version 1.0)
- Struts2 拦截器实现用户登录(关键代码)
- C语言怎么将用户账号密码写入文件实现登录注册功能?
- PHP用户登录后跳转回上一访问页面的实现思路及代码
- C语言怎么将用户账号密码写入文件实现登录注册功能?
- 使用Jquery打造最佳用户体验的登录页面的实现代码
- Android实战简易教程-第二十三枪(基于Baas的用户注册和登录模块实现!)
- SSH系列一:实现用户登录模块
- jsp中未登录用户也可以浏览页面的功能实现代码
- 简单的asp.net模拟邮箱系统基础实现(二 (1)具体版块功能的实现及关键代码之注册页面)
- PHP用户登录注册模块实现
- Struts2中注册登录模块配置文件路径更改
- 解决root用户ssh配置无密码登陆/hadoop用户照仿可以实现相同功能:hadoop用户登录并且把命令的所有root换成home/hadoop
- 基于socket,实现用户注册,用户登录,以及文件上传的例子
- ASP.NET Core中实现用户登录验证的最低配置示例代码
- 用JavaScript实现用户登录验证、注册信息格式检验(附代码)
- WAS应用系列:WAS6 自定义用户注册接口代码 + 企业应用安全角色配置 + WAS安全配置 实现统一灵活的集成授权
- 完成用户注册、登录页面,实现数据的真实操作。
- 使用Jquery打造最佳用户体验的登录页面的实现代码
- 淘淘商城系列——单点登录之用户注册页面实现