登录和注册(struts2+hibernate+spring)

一:添加三框架jar包

 

二:model层(student.java)    

Java代码   收藏代码
  1. package com.wdpc.ss2h.model;  
  2.   
  3. public class Student {  
  4.     private String id;  
  5.     private String userName;//创建姓名  
  6.     private String userPwd;//创建密码  
  7.   
  8.     //无参构造  
  9.     public Student() {  
  10.         super();  
  11.     }  
  12.   
  13.     //有参构造  
  14.     public Student(String userName, String userPwd) {  
  15.         super();  
  16.         this.userName = userName;  
  17.         this.userPwd = userPwd;  
  18.     }  
  19.   
  20.     //get,set方法  
  21.     public String getId() {  
  22.         return id;  
  23.     }  
  24.   
  25.     public void setId(String id) {  
  26.         this.id = id;  
  27.     }  
  28.   
  29.     public String getUserName() {  
  30.         return userName;  
  31.     }  
  32.   
  33.     public void setUserName(String userName) {  
  34.         this.userName = userName;  
  35.     }  
  36.   
  37.     public String getUserPwd() {  
  38.         return userPwd;  
  39.     }  
  40.   
  41.     public void setUserPwd(String userPwd) {  
  42.         this.userPwd = userPwd;  
  43.     }  
  44. }  

   //model层 student配置文件(Student.hbm.xml) 

Java代码   收藏代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"  
  3. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">  
  4. <hibernate-mapping>  
  5.     <class name="com.wdpc.ss2h.model.Student" table="student">  
  6.         <id name="id" type="java.lang.String" column="id">  
  7.             <generator class="uuid.hex"></generator>  
  8.         </id>  
  9.         <property name="userName" type="java.lang.String" column="userName" />  
  10.         <property name="userPwd" type="java.lang.String" column="userPwd" />  
  11.     </class>  
  12. </hibernate-mapping>  

    此映射文件要放到model层下,和student类放在一起

   //dao层 (StudentDao.java) 

Java代码   收藏代码
  1. package com.wdpc.ss2h.dao;  
  2.   
  3. import com.wdpc.ss2h.model.Student;  
  4.   
  5. public interface StudentDao {  
  6.     //登录  
  7.     public Student findName(Student student) throws Exception;  
  8.     //注册  
  9.     public void createStudent(Student student) throws Exception;  
  10. }  

     创建dao层接口

   //实现dao层(StudentDaoImpl.java)

Java代码   收藏代码
  1. package com.wdpc.ss2h.dao.impl;  
  2.   
  3. import java.util.List;  
  4. import org.hibernate.Query;  
  5. import org.hibernate.SessionFactory;  
  6. import com.wdpc.ss2h.dao.StudentDao;  
  7. import com.wdpc.ss2h.model.Student;  
  8.   
  9. public class StudentDaoImpl implements StudentDao {  
  10.     private SessionFactory sessionFactory;  
  11.     //注册  
  12.     public void createStudent(Student student) throws Exception {  
  13.         sessionFactory.getCurrentSession().save(student);  
  14.     }  
  15.   
  16.     //登录  
  17.     public Student findName(Student student) throws Exception {  
  18.         Query query = sessionFactory.getCurrentSession().createQuery(  
  19.         "from Student where userName=:name and userPwd=:password");  
  20.         query.setParameter("name",student.getUserName());  
  21.         query.setParameter("password",student.getUserPwd());  
  22.         List<Student> list = query.list();          
  23.         if (list.size() > 0)  
  24.             return list.get(0);  
  25.         else  
  26.             return null;  
  27.     }  
  28.   
  29.     public void setSessionFactory(SessionFactory sessionFactory) {  
  30.         this.sessionFactory = sessionFactory;  
  31.     }     
  32. }  

    实现StudentDao.java接口方法

  //service层(StudentService.java)

Java代码   收藏代码
  1. package com.wdpc.ss2h.service;  
  2.   
  3. import com.wdpc.ss2h.model.Student;  
  4.   
  5. public interface StudentService {  
  6.     //登录  
  7.     public Student findName(Student student) throws Exception;  
  8.     //注册  
  9.     public void createStudent(Student student) throws Exception;  
  10. }  

  //实现service层(StudentServiceImpl.java)

Java代码   收藏代码
  1. package com.wdpc.ss2h.service.impl;  
  2.   
  3. import com.wdpc.ss2h.dao.StudentDao;  
  4. import com.wdpc.ss2h.model.Student;  
  5. import com.wdpc.ss2h.service.StudentService;  
  6.   
  7. public class StudentServiceImpl implements StudentService {  
  8.     private StudentDao studentDao;  
  9.       
  10.     public void createStudent(Student student) throws Exception {  
  11.         studentDao.createStudent(student);  
  12.     }  
  13.   
  14.     public Student findName(Student student) throws Exception {  
  15.         return studentDao.findName(student);  
  16.     }  
  17.   
  18.     public void setStudentDao(StudentDao studentDao) {  
  19.         this.studentDao = studentDao;  
  20.     }     
  21. }  

  //BaseAction.java

Java代码   收藏代码
  1. package com.wdpc.ss2h.comms;  
  2.   
  3. import java.util.Map;  
  4. import javax.servlet.http.HttpServletRequest;  
  5. import javax.servlet.http.HttpServletResponse;  
  6. import org.apache.struts2.interceptor.ServletRequestAware;  
  7. import org.apache.struts2.interceptor.ServletResponseAware;  
  8. import org.apache.struts2.interceptor.SessionAware;  
  9. import com.opensymphony.xwork2.ActionSupport;  
  10.   
  11. public abstract class BaseAction extends ActionSupport implements  
  12.         ServletResponseAware, ServletRequestAware, SessionAware {  
  13.     protected HttpServletResponse response;  
  14.     protected HttpServletRequest request;  
  15.     protected Map<String, Object> session;  
  16.   
  17.     public void setServletResponse(HttpServletResponse response) {  
  18.         this.response = response;  
  19.     }  
  20.   
  21.     public void setServletRequest(HttpServletRequest request) {  
  22.         this.request = request;  
  23.     }  
  24.   
  25.     public void setSession(Map<String, Object> session) {  
  26.         this.session = session;  
  27.     }  
  28.   
  29.     public HttpServletResponse getResponse() {  
  30.         return response;  
  31.     }  
  32.   
  33.     public void setResponse(HttpServletResponse response) {  
  34.         this.response = response;  
  35.     }  
  36.   
  37.     public HttpServletRequest getRequest() {  
  38.         return request;  
  39.     }  
  40.   
  41.     public void setRequest(HttpServletRequest request) {  
  42.         this.request = request;  
  43.     }  
  44.   
  45.     public Map getSession() {  
  46.         return session;  
  47.     }  
  48. }  

  //action层 (StudentAction.java) 

Java代码   收藏代码
  1. package com.wdpc.ss2h.action;  
  2.   
  3. import java.awt.Color;  
  4. import java.awt.Font;  
  5. import java.awt.Graphics;  
  6. import java.awt.image.BufferedImage;  
  7. import java.io.ByteArrayInputStream;  
  8. import java.io.ByteArrayOutputStream;  
  9. import java.io.IOException;  
  10. import java.io.InputStream;  
  11. import java.util.Map;  
  12. import java.util.Random;  
  13. import javax.imageio.ImageIO;  
  14. import com.opensymphony.xwork2.ModelDriven;  
  15. import com.wdpc.ss2h.comms.BaseAction;  
  16. import com.wdpc.ss2h.model.Student;  
  17. import com.wdpc.ss2h.service.StudentService;  
  18.   
  19. public class StudentAction extends BaseAction implements ModelDriven<Student>{  
  20.     private Student student;  
  21.     private InputStream imageStream;  
  22.     private Map<String, Object> session;  
  23.     private StudentService studentService;  
  24.     private String randCode;//验证码  
  25.     private String message;//显示错误信息  
  26.       
  27.     public String index(){  
  28.         return "index";  
  29.     }  
  30.   
  31.     // 验证码  
  32.     public String getCheckCodeImage(String str, int show,  
  33.             ByteArrayOutputStream output) {  
  34.         Random random = new Random();  
  35.         BufferedImage image = new BufferedImage(8030,  
  36.                 BufferedImage.TYPE_3BYTE_BGR);  
  37.         Font font = new Font("Arial", Font.PLAIN, 24);  
  38.         int distance = 18;  
  39.         Graphics d = image.getGraphics();  
  40.         d.setColor(Color.WHITE);  
  41.         d.fillRect(00, image.getWidth(), image.getHeight());  
  42.         d.setColor(new Color(random.nextInt(100) + 100,  
  43.                 random.nextInt(100) + 100, random.nextInt(100) + 100));  
  44.         for (int i = 0; i < 10; i++) {  
  45.             d.drawLine(random.nextInt(image.getWidth()), random.nextInt(image  
  46.                     .getHeight()), random.nextInt(image.getWidth()), random  
  47.                     .nextInt(image.getHeight()));  
  48.         }  
  49.         d.setColor(Color.BLACK);  
  50.         d.setFont(font);  
  51.         String checkCode = "";  
  52.         char tmp;  
  53.         int x = -distance;  
  54.         for (int i = 0; i < show; i++) {  
  55.             tmp = str.charAt(random.nextInt(str.length() - 1));  
  56.             checkCode = checkCode + tmp;  
  57.             x = x + distance;  
  58.             d.setColor(new Color(random.nextInt(100) + 50,  
  59.                     random.nextInt(100) + 50, random.nextInt(100) + 50));  
  60.             d.drawString(tmp + "", x, random.nextInt(image.getHeight()  
  61.                     - (font.getSize()))  
  62.                     + (font.getSize()));  
  63.         }  
  64.         d.dispose();  
  65.         try {  
  66.             ImageIO.write(image, "jpg", output);  
  67.         } catch (IOException e) {  
  68.             e.printStackTrace();  
  69.         }  
  70.         return checkCode;  
  71.     }  
  72.   
  73.     public String execute() throws Exception {  
  74.         ByteArrayOutputStream output = new ByteArrayOutputStream();  
  75.         String checkCode = getCheckCodeImage(  
  76.                 "ABCDEFGHJKLMNPQRSTUVWXYZ123456789"4, output);  
  77.         this.session.put("CheckCode", checkCode);  
  78.         // 这里将output stream转化为 inputstream  
  79.         this.imageStream = new ByteArrayInputStream(output.toByteArray());  
  80.         output.close();  
  81.         return SUCCESS;  
  82.     }  
  83.       
  84.     //登录  
  85.     public String login(){  
  86.         String CheckCode = (String)request.getSession().getAttribute("CheckCode");  
  87.         if(!(CheckCode.equalsIgnoreCase(randCode))){  
  88.             message ="验证码输入有误!";  
  89.             return "index";                   
  90.         }  
  91.         try {  
  92.             studentService.findName(student);  
  93.             return "login";           
  94.         } catch (Exception e) {  
  95.             e.printStackTrace();  
  96.             return "index";  
  97.         }         
  98.     }  
  99.       
  100.     public String register(){  
  101.         return "register";  
  102.     }  
  103.       
  104.     //注册  
  105.     public String createStudent(){  
  106.         try{  
  107.             studentService.createStudent(student);  
  108.             return "success";  
  109.         } catch (Exception e) {  
  110.             e.printStackTrace();  
  111.             return "index";  
  112.         }  
  113.     }  
  114.       
  115.     public Student getStudent() {  
  116.         return student;  
  117.     }  
  118.   
  119.     public void setStudent(Student student) {  
  120.         this.student = student;  
  121.     }  
  122.   
  123.     public InputStream getImageStream() {  
  124.         return imageStream;  
  125.     }  
  126.   
  127.     public void setImageStream(InputStream imageStream) {  
  128.         this.imageStream = imageStream;  
  129.     }  
  130.   
  131.     public Map<String, Object> getSession() {  
  132.         return session;  
  133.     }  
  134.   
  135.     public void setSession(Map<String, Object> session) {  
  136.         this.session = session;  
  137.     }     
  138.       
  139.     public Student getModel() {  
  140.         student = new Student();  
  141.         return student;  
  142.     }  
  143.   
  144.     public StudentService getStudentService() {  
  145.         return studentService;  
  146.     }  
  147.   
  148.     public void setStudentService(StudentService studentService) {  
  149.         this.studentService = studentService;  
  150.     }  
  151.       
  152.     public String getRandCode() {  
  153.         return randCode;  
  154.     }  
  155.   
  156.     public void setRandCode(String randCode) {  
  157.         this.randCode = randCode;  
  158.     }  
  159.   
  160.     public String getMessage() {  
  161.         return message;  
  162.     }  
  163.   
  164.     public void setMessage(String message) {  
  165.         this.message = message;  
  166.     }             
  167. }  

  //StudentAction-createStudent-validation.xml配置注册验证 

Java代码   收藏代码
  1. <!DOCTYPE validators PUBLIC  
  2.         "-//OpenSymphony Group//XWork Validator 1.0.2//EN"  
  3.         "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">  
  4. <validators>  
  5.     <field name="userName">  
  6.         <field-validator type="requiredstring">  
  7.             <message>用户名必须填写</message>  
  8.         </field-validator>  
  9.         <field-validator type="stringlength">  
  10.             <param name="minLength">6</param>  
  11.             <param name="maxLength">12</param>  
  12.             <message>用户名必须在${minLength}~${maxLength}位之间</message>  
  13.         </field-validator>  
  14.     </field>  
  15.     <field name="userPwd">  
  16.         <field-validator type="requiredstring">  
  17.             <param name="trim">true</param>  
  18.             <message>密码必须填写</message>  
  19.         </field-validator>  
  20.         <field-validator type="stringlength">  
  21.             <param name="minLength">6</param>  
  22.             <param name="maxLength">20</param>  
  23.             <message>密码必须在${minLength}~${maxLength}位之间</message>  
  24.         </field-validator>          
  25.     </field>  
  26. </validators>  

     此文件放到action层,和StudentAction.java放在一起

    //StudentAction-login-validation.xml配置登录验证   

Java代码   收藏代码
  1. <!DOCTYPE validators PUBLIC  
  2.         "-//OpenSymphony Group//XWork Validator 1.0.2//EN"  
  3.         "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">  
  4. <validators>  
  5.     <field name="userName">  
  6.         <field-validator type="requiredstring">  
  7.             <message>用户名必须填写</message>  
  8.         </field-validator>  
  9.         <field-validator type="stringlength">  
  10.             <param name="minLength">6</param>  
  11.             <param name="maxLength">12</param>  
  12.             <message>用户名必须在${minLength}~${maxLength}位之间</message>  
  13.         </field-validator>  
  14.     </field>  
  15.     <field name="userPwd">  
  16.         <field-validator type="requiredstring">  
  17.             <message>请正确填写密码</message>  
  18.         </field-validator>  
  19.         <field-validator type="stringlength">  
  20.             <param name="minLength">6</param>  
  21.             <param name="maxLength">20</param>  
  22.             <message>密码必须在${minLength}~${maxLength}位之间</message>  
  23.         </field-validator>          
  24.     </field>  
  25. </validators>  

     此文件放到action层,和StudentAction.java放在一起

  

   //配置hibernate.cfg.xml  

Java代码   收藏代码
  1. <?xml version='1.0' encoding='utf-8'?>  
  2. <!DOCTYPE hibernate-configuration PUBLIC  
  3.         "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
  4.         "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  
  5.   
  6. <hibernate-configuration>  
  7.     <session-factory>  
  8.         <!-- 设置使用数据库的语言 -->  
  9.         <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>  
  10.         <property name="Hibernate.current_session_context_class">thread</property>  
  11.         <!-- 设置是否显示执行的语言 -->  
  12.         <property name="show_sql">true</property>  
  13.         <!--property name="hbm2ddl.auto">create</property-->  
  14.         <!-- 数据库连接属性设置 -->  
  15.         <property name="connection.driver_class">com.mysql.jdbc.Driver</property>  
  16.         <property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8</property>  
  17.         <property name="connection.username">root</property>  
  18.         <property name="connection.password">wdpc</property>  
  19.         <!-- 设置 c3p0连接池的属性-->  
  20.         <property name="connection.useUnicode">true</property>  
  21.         <property name="hibernate.c3p0.max_statements">100</property>  
  22.         <property name="hibernate.c3p0.idle_test_period">3000</property>  
  23.         <property name="hibernate.c3p0.acquire_increment">2</property>  
  24.         <property name="hibernate.c3p0.timeout">5000</property>  
  25.         <property name="hibernate.connection.provider_class">  
  26.             org.hibernate.connection.C3P0ConnectionProvider  
  27.         </property>  
  28.         <property name="hibernate.c3p0.validate">true</property>  
  29.         <property name="hibernate.c3p0.max_size">3</property>  
  30.         <property name="hibernate.c3p0.min_size">1</property>  
  31.         <!-- 加载映射文件-->  
  32.         <mapping resource="com/wdpc/ss2h/model/Student.hbm.xml" />  
  33.     </session-factory>  
  34. </hibernate-configuration>  

     此配置文件放在src目录下

 

   //配置struts.xml文件   

Java代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8" ?>  
  2. <!DOCTYPE struts PUBLIC  
  3.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
  4.     "http://struts.apache.org/dtds/struts-2.0.dtd">  
  5.   
  6. <struts>  
  7.     <!-- 设置一些全局的常量开关 -->  
  8.     <constant name="struts.i18n.encoding" value="UTF-8" />  
  9.     <constant name="struts.action.extension" value="do,action" />  
  10.     <constant name="struts.serve.static.browserCache " value="false" />  
  11.     <constant name="struts.configuration.xml.reload" value="true" />  
  12.     <constant name="struts.devMode" value="true" />  
  13.     <constant name="struts.enable.DynamicMethodInvocation" value="false" />  
  14.       
  15.     <package name="ss2h" extends="struts-default">  
  16.         <action name="index" class="StudentAction" method="index">  
  17.             <result name="index">/WEB-INF/page/login.jsp</result>  
  18.         </action>  
  19.         <action name="checkCode" class="StudentAction" method="execute">  
  20.             <result name="success" type="stream">  
  21.                 <param name="contentType">image/jpeg</param>  
  22.                 <param name="contentCharSet">UTF-8</param>  
  23.                 <param name="inputName">imageStream</param>  
  24.             </result>  
  25.         </action>  
  26.         <action name="login" class="StudentAction" method="login">  
  27.             <result name="login">/WEB-INF/page/success.jsp</result>  
  28.             <result name="index">/WEB-INF/page/login.jsp</result>  
  29.             <result name="input">/WEB-INF/page/login.jsp</result>  
  30.         </action>  
  31.         <action name="register" class="StudentAction" method="register">  
  32.             <result name="register">/WEB-INF/page/register.jsp</result>  
  33.         </action>  
  34.         <action name="createStudent" class="StudentAction" method="createStudent">  
  35.             <result name="success">/WEB-INF/page/success.jsp</result>  
  36.             <result name="index">/WEB-INF/page/register.jsp</result>  
  37.             <result name="input">/WEB-INF/page/register.jsp</result>  
  38.         </action>  
  39.     </package>  
  40. </struts>  

     此配置文件放在src目录下

 

   //配置spring(applicationContext.xml)文件  

Java代码   收藏代码
  1. <beans xmlns="http://www.springframework.org/schema/beans"  
  2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"  
  3.     xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"  
  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
  5.            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd  
  6.            http://www.springframework.org/schema/context  
  7.            http://www.springframework.org/schema/context/spring-context-2.5.xsd             
  8.            http://www.springframework.org/schema/aop  
  9.            http://www.springframework.org/schema/aop/spring-aop-2.5.xsd  
  10.            http://www.springframework.org/schema/tx  
  11.            http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">  
  12.     <context:annotation-config />  
  13.     <context:component-scan base-package="com.wdpc.ss2h" />  
  14.     <aop:aspectj-autoproxy />  
  15.     <bean id="sessionFactory"  
  16.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  17.         <property name="configLocation" value="classpath:hibernate.cfg.xml">  
  18.         </property>  
  19.     </bean>  
  20.     <bean id="studentDao" class="com.wdpc.ss2h.dao.impl.StudentDaoImpl">  
  21.         <property name="sessionFactory" ref="sessionFactory" />  
  22.     </bean>  
  23.     <bean id="studentService" class="com.wdpc.ss2h.service.impl.StudentServiceImpl">  
  24.         <property name="studentDao" ref="studentDao" />  
  25.     </bean>  
  26.         <bean id="StudentAction" class="com.wdpc.ss2h.action.StudentAction" scope="prototype">  
  27.         <property name="studentService" ref="studentService" />  
  28.     </bean>  
  29.     <bean id="txManager"  
  30.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  31.         <property name="sessionFactory" ref="sessionFactory" />  
  32.     </bean>  
  33.     <tx:annotation-driven transaction-manager="txManager" />  
  34.     <tx:advice id="txAdvice" transaction-manager="txManager">  
  35.         <tx:attributes>  
  36.             <tx:method name="find*" read-only="true"/>  
  37.             <tx:method name="*" rollback-for="Exception" />  
  38.         </tx:attributes>  
  39.     </tx:advice>  
  40.     <aop:config>  
  41.         <aop:pointcut id="txPointcut"  
  42.             expression="execution(* com.wdpc.ss2h.service..*.*(..))" />  
  43.         <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" />  
  44.     </aop:config>  
  45. </beans>  

    此配置文件放在src目录下

 

   //配置web.xml   

Java代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="2.5"   
  3.     xmlns="http://java.sun.com/xml/ns/javaee"   
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   
  6.     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  
  7.     <context-param>  
  8.         <param-name>contextConfigLocation</param-name>  
  9.         <param-value>classpath:applicationContext.xml</param-value>  
  10.     </context-param>  
  11.     <listener>  
  12.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  13.     </listener>  
  14.     <filter>  
  15.         <filter-name>struts2</filter-name>  
  16.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  17.     </filter>  
  18.     <filter-mapping>  
  19.         <filter-name>struts2</filter-name>  
  20.         <url-pattern>/*</url-pattern>  
  21.     </filter-mapping>  
  22.   <welcome-file-list>  
  23.     <welcome-file>index.jsp</welcome-file>  
  24.   </welcome-file-list>  
  25. </web-app>  

   

   //index.jap页面  

Java代码   收藏代码
  1. <%@ page language="java" pageEncoding="utf-8"%>  
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  3. <c:redirect url="/index.do"/>  

 

   //login.jsp页面  

Java代码   收藏代码
  1. <%@ page language="java" pageEncoding="utf-8"%>  
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  3. <c:set var="basePath" value="${pageContext.request.contextPath}" />  
  4. <%@ taglib uri="/struts-tags" prefix="s"%>  
  5.   
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  7. <html>  
  8.   <head>  
  9.     <script type="text/javascript">  
  10.         function change(obj){  
  11.             obj.src="${basePath}/checkCode.do?time=" + new Date().getTime();  
  12.         }  
  13.     </script>  
  14.   </head>  
  15.   <body>  
  16.     <div>  
  17.     <form action="${basePath}/login.do" method="post">  
  18.         <div style="color: red;">  
  19.             <s:fielderror />  
  20.             ${message}  
  21.         </div>  
  22.         <div>  
  23.             <label>用户名:</label>  
  24.             <label><input type="text" name="userName" /></label><br />  
  25.             <label>密&nbsp;&nbsp;&nbsp;&nbsp;碼:</label>  
  26.             <label><input type="password" name="userPwd" /></label><br />  
  27.             <label>验证碼:</label>           
  28.             <label><input type="text" name="randCode" /></label><br />  
  29.             <label>&nbsp;&nbsp;&nbsp;&nbsp;<img src="${basePath}/checkCode.do" width="100px"   height="25px" alt="看不清,换一张" style="cursor: pointer;" οnclick="change(this)" /></label>  
  30.         </div>  
  31.         <div>  
  32.             <label><input type="submit" value="登錄" /></label>  
  33.             <label><input type="button" value="註冊" οnclick="window.location='${basePath}/register.do'"/></label>  
  34.         </div>  
  35.     </form>  
  36.     </div>  
  37.   </body>  
  38. </html>  

 

   //register.jsp页面   

Java代码   收藏代码
  1. <%@ page language="java" pageEncoding="utf-8"%>  
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  3. <c:set var="bathPath" value="${pageContext.request.contextPath}"/>  
  4. <%@ taglib uri="/struts-tags" prefix="s"%>  
  5.   
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  7. <html>  
  8.   <head>  
  9.   </head>  
  10.   <body>  
  11.     <div>  
  12.     <form action="${bathPath}/createStudent.do" method="post">  
  13.         <div style="color: red;"><s:fielderror /></div>  
  14.         <div>  
  15.             <label>用&nbsp;户&nbsp;名:</label>  
  16.             <input type="text" name="userName"/>  
  17.             <label id="chage1"></label><br/>  
  18.             <label>*正确填写用户名,6-12位之间请用英文小写、下划线、数字。</label><br/>  
  19.             <label>用户密码:</label>  
  20.             <input type="password" name="userPwd" /><br/>  
  21.             <label>*正确填写密码,6-12位之间请用英文小写、下划线、数字。</label><br/>  
  22.             <label>确认密码:</label>  
  23.             <input type="password" name="pwd2"/><br/>  
  24.             <label>*两次密码要一致,请用英文小写、下划线、数字。</label><br/>  
  25.         </div>  
  26.         <div>  
  27.             <label><input type="submit" value="註冊" /></label>  
  28.             <label><input type="reset" value="取消" /></label>  
  29.         </div>  
  30.     </form>  
  31.     </div>  
  32.   </body>  
  33. </html>  

 

   //登录和注册成功页面success.jsp  

Java代码   收藏代码
  1. <%@ page language="java" pageEncoding="utf-8"%>  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  3. <html>  
  4.   <head>  
  5.   </head>  
  6.   <body>  
  7.     登录成功!  
  8.     注册成功!  
  9.   </body>  
  10. </html>  

     此login.jsp,register.jsp,success.jsp放到/WEB-INF/page目录下:     

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值