您的位置:首页 > 编程语言

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐