前面写了jsp+servlet来实现登录注册功能,虽然运用了MVC的思想但是action-dao-service,但是还是分层的不够彻底,现在学习了框架准备用spring+springmvc+mybatis框架来实现登录注册,具有一定的参考能力,小伙伴们可以参考一下。
-lfy
项目图: 需要的jar包:
首先是框架的整合:
mybatis和spring框架整合配置文件:
1 xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 4 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:mvc="http://www.springframework.org/schema/mvc" 7 xsi:schemaLocation=" 8 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 9 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 10 http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 11 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 12 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 13 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 14 15 16 17 18 <context:annotation-config /> 19 <context:component-scan base-package="com.how2java.service" /> 20 21 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 22 <property name="driverClassName"> 23 <value>com.mysql.jdbc.Drivervalue> 24 property> 25 <property name="url"> 26 <value>jdbc:mysql://localhost:3306/jdbc_db?characterEncoding=UTF-8value> 27 28 property> 29 <property name="username"> 30 <value>rootvalue> 31 property> 32 <property name="password"> 33 <value>123value> 34 property> 35 bean> 36 37 38 <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean"> 39 <property name="typeAliasesPackage" value="com.how2java.pojo" /> 40 <property name="dataSource" ref="dataSource"/> 41 <property name="mapperLocations" value="classpath:com/how2java/mapper/*.xml"/> 42 bean> 43 44 <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> 45 <property name="basePackage" value="com.how2java.mapper"/> 46 bean> 47 beans>
spring和springmvc框架整合配置文件:
1 xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" 4 xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xmlns:mvc="http://www.springframework.org/schema/mvc" 7 xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd 8 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 9 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 10 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 11 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 12 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 13 14 15 16 <context:annotation-config/> 17 18 <context:component-scan base-package="com.how2java.controller"> 19 <context:include-filter type="annotation" 20 expression="org.springframework.stereotype.Controller"/> 21 context:component-scan> 22 23 <mvc:annotation-driven /> 24 25 <mvc:default-servlet-handler /> 26 27 28 <bean 29 class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 30 <property name="viewClass" 31 value="org.springframework.web.servlet.view.JstlView" /> 32 <property name="prefix" value="/WEB-INF/jsp/" /> 33 <property name="suffix" value=".jsp" /> 34 bean> 35 beans>
数据库配置文件:
1 # Global logging configuration 2 log4j.rootLogger=ERROR, stdout 3 # MyBatis logging configuration... 4 log4j.logger.com.how2java=TRACE 5 # Console output... 6 log4j.appender.stdout=org.apache.log4j.ConsoleAppender 7 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 8 log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
控制器:controller
1 package com.how2java.controller; 2 3 import javax.servlet.http.HttpServletRequest; 4 import javax.servlet.http.HttpSession; 5 6 import org.apache.ibatis.annotations.Param; 7 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.stereotype.Controller; 9 import org.springframework.web.bind.annotation.RequestMapping; 10 import org.springframework.web.servlet.ModelAndView; 11 12 import com.how2java.mapper.CategoryMapper; 13 import com.how2java.pojo.Category; 14 import com.how2java.service.CategoryService; 15 16 // 告诉spring mvc这是一个控制器类 17 @Controller 18 @RequestMapping("") 19 public class CategoryController { 20 @Autowired 21 CategoryService categoryService; 22 @Autowired 23 CategoryMapper categoryMaper; 24 25 @RequestMapping("login") 26 public String loginIndex(){ 27 return "hh"; 28 } 29 @RequestMapping("register") 30 public String registerIndex(){ 31 return "pass"; 32 } 33 34 @RequestMapping("select") 35 public String login(Category category,HttpServletRequest request){ 36 HttpSession session = request.getSession(); 37 boolean loginType = categoryService.login(category.getUsername(),category.getPassword()); 38 if(loginType){ 39 //如果验证通过,则将用户信息传到前台 40 Category user = categoryMaper.select(category.getUsername()); 41 session.setAttribute("username",user.getUsername()); 42 session.setAttribute("realname", user.getRealname()); 43 session.setAttribute("password", user.getPassword()); 44 session.setAttribute("sex", user.getSex()); 45 //request.setAttribute("message","登录成功!"); 46 //并跳转到success.jsp页面 47 return "xinxi"; 48 }else{ 49 request.setAttribute("message","用户名密码错误!"); 50 return "hh"; 51 } 52 } 53 54 @RequestMapping("add") 55 public ModelAndView add(Category category){ 56 ModelAndView mav = new ModelAndView(); 57 int cot = categoryService.count(category.getUsername()); 58 if(category.getUsername()!=null&&category.getUsername()!=""){ 59 if(cot>=1){ 60 mav.addObject("message","用户名已存在"); 61 mav.setViewName("pass"); 62 }else{ 63 categoryService.add(category); 64 mav.setViewName("hh"); 65 } 66 } 67 return mav; 68 } 69 }
mapper类:
1 import java.util.List; 2 3 import com.how2java.pojo.Category; 4 5 public interface CategoryMapper { 6 7 8 public int add(Category category); 9 10 11 public int delete(int id); 12 13 14 public Category get(int id); 15 16 17 public int update(Category category); 18 19 public Category select(String username); 20 public Listlist(); 21 22 23 public int count(String username); 24 }
CategoryMapper.xml
1 xml version="1.0" encoding="UTF-8"?> 2 DOCTYPE mapper 3 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5 6 <mapper namespace="com.how2java.mapper.CategoryMapper"> 7 <insert id="add" parameterType="Category" > 8 insert into userinfo (username,realname,password,sex ) values (#{username},#{realname},#{password},#{sex}) 9 insert> 10 11 <delete id="delete" parameterType="_int" > 12 delete from userinfo where id= #{id} 13 delete> 14 15 <select id="get" parameterType="_int" resultType="Category"> 16 select * from userinfo where username= #{username} 17 select> 18 19 <update id="update" parameterType="Category" > 20 update userinfo set name=#{name} where username=#{username} 21 update> 22 <select id="list" resultType="Category"> 23 select * from userinfo 24 select> 25 26 <select id="count" resultType="_int"> 27 select count(*) FROM userinfo where username =#{username} 28 select> 29 <select id="select" resultType="Category"> 30 select * from userinfo where username= #{username} 31 32 select> 33 mapper>
pojo实体类:
package com.how2java.pojo; public class Category { private int id; private String username; private String realname; private String password; private String sex; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getRealname() { return realname; } public void setRealname(String realname) { this.realname = realname; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public int getId() { return id; } public void setId(int id) { this.id = id; } @Override public String toString() { return "Category [id=" + id + ", username=" + username + ", realname=" + realname + ", password=" + password + ", sex=" + sex + "]"; } }
service实现类:
1 package com.how2java.service.impl; 2 3 import java.util.List; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.stereotype.Service; 7 8 import com.how2java.mapper.CategoryMapper; 9 import com.how2java.pojo.Category; 10 import com.how2java.service.CategoryService; 11 12 @Service 13 public class CategoryServiceImpl implements CategoryService{ 14 @Autowired 15 CategoryMapper categoryMapper; 16 17 18 public Listlist(){ 19 return categoryMapper.list(); 20 } 21 22 23 public int add(Category category) { 24 return categoryMapper.add(category); 25 } 26 27 28 29 public int count(String username) { 30 return categoryMapper.count(username); 31 } 32 33 34 public int delete(int id) { 35 return categoryMapper.delete(id); 36 } 37 public boolean login(String username, String password) { 38 // TODO Auto-generated method stub 39 Category user = categoryMapper.select(username); 40 if(user!=null){ 41 if (user.getUsername().equals(username) && user.getPassword().equals(password)){ 42 return true; 43 } 44 45 46 } 47 return false; 48 } 49 }
service接口类:
1 package com.how2java.service; 2 3 import java.util.List; 4 5 import org.apache.ibatis.annotations.Param; 6 7 import com.how2java.pojo.Category; 8 9 public interface CategoryService { 10 11 Listlist(); 12 13 int add(Category category); 14 15 int count(@Param("username")String username); 16 17 int delete(@Param("id")int id); 18 19 public boolean login(String userName,String password); 20 }
web.xml
1 xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xmlns:web="http://java.sun.com/xml/ns/javaee" 5 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> 6 7 8 <context-param> 9 <param-name>contextConfigLocationparam-name> 10 <param-value>classpath:applicationContext.xmlparam-value> 11 context-param> 12 <listener> 13 <listener-class>org.springframework.web.context.ContextLoaderListenerlistener-class> 14 listener> 15 16 17 18 <servlet> 19 <servlet-name>mvc-dispatcherservlet-name> 20 <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class> 21 22 <init-param> 23 <param-name>contextConfigLocationparam-name> 24 <param-value>classpath:springMVC.xmlparam-value> 25 init-param> 26 <load-on-startup>1load-on-startup> 27 servlet> 28 <servlet-mapping> 29 <servlet-name>mvc-dispatcherservlet-name> 30 <url-pattern>/url-pattern> 31 servlet-mapping> 32 33 34 <filter> 35 <filter-name>encodingFilterfilter-name> 36 <filter-class>org.springframework.web.filter.CharacterEncodingFilterfilter-class> 37 <init-param> 38 <param-name>encodingparam-name> 39 <param-value>UTF-8param-value> 40 init-param> 41 <init-param> 42 <param-name>forceEncodingparam-name> 43 <param-value>trueparam-value> 44 init-param> 45 filter> 46 47 <filter-mapping> 48 <filter-name>encodingFilterfilter-name> 49 <url-pattern>/*url-pattern> 50 filter-mapping> 51 <welcome-file-list> 52 <welcome-file>hh.jspwelcome-file> 53 welcome-file-list> 54 55 56 web-app>
登录页面:hh.jsp
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8" %> 2 <% 3 String path = request.getContextPath(); 4 %> 5 6 DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 7 <html> 8 <head> 9 <title>后台管理系统title> 10 <meta http-equiv=Content-Type content="text/html; charset=utf-8"> 11 12 <meta http-equiv="pragma" content="no-cache"> 13 <meta http-equiv="cache-control" content="no-cache"> 14 <meta http-equiv="expires" content="0"> 15 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 16 <meta http-equiv="description" content="This is my page"> 17 <style type="text/css"> 18 .neon { 19 FILTER: glow(color = #002E60, strength = 3) 20 } 21 22 DIV { 23 WIDTH: 70px 24 } 25 26 BODY { 27 MARGIN: 0px 28 } 29 30 BODY { 31 MARGIN-TOP: 0px; 32 SCROLLBAR-FACE-COLOR: #005fc5; 33 FONT-SIZE: 12px; 34 BACKGROUND: #ffffff; 35 SCROLLBAR-HIGHLIGHT-COLOR: #799ae1; 36 SCROLLBAR-SHADOW-COLOR: #799ae1; 37 SCROLLBAR-3DLIGHT-COLOR: #005fc5; 38 SCROLLBAR-ARROW-COLOR: #ffffff; 39 SCROLLBAR-TRACK-COLOR: #aabfec; 40 SCROLLBAR-DARKSHADOW-COLOR: #799ae1 41 } 42 STYLE> 43 <LINK href="<%=path%>/images/duan_1.css" type=text/css rel=stylesheet> 44 <META content="MSHTML 6.00.2800.1106" name=GENERATOR> 45 <style type="text/css"> 46 .style6 { 47 COLOR: #0000ff 48 } 49 50 .STYLE7 { 51 COLOR: #003366; 52 font-size: 12px; 53 } 54 style> 55 <script type="text/javascript"> 56 function dosubmit() { 57 var th = document.form2; 58 if (th.username.value == "") { 59 alert("用户名不能为空"); 60 th.username.focus(); 61 return; 62 } 63 64 if (th.password.value == "") { 65 alert("密码不能为空"); 66 th.password.focus(); 67 return; 68 } 69 //alert(${message}); 70 //console.log(${message}); 71 72 th.action="<%=path%>/select" 73 th.submit(); 74 } 75 script> 76 77 head> 78 <h1>${message}h1> 79 <body bgColor=#ffffff 80 onload="MM_preloadImages('<%=path%>/images/ok_2.jpg', '<%=path%>/images/fh_2.jpg')"> 81 <form name="form2" method="Post"> 82 <table height=470 cellSpacing=0 cellPadding=0 width=580 aligen=center 83 border=0> 84 <tbody> 85 <tr> 86 <td colSpan=3 height=9 /> 87 tr> 88 <tr> 89 <td vAlign=top width=8 background="<%=path%>/images/dhpddw.gif" 90 rowSpan=2> 91 td> 92 <td background="<%=path%>/images/h-1.gif" height=9>td> 93 <td width=9 height=9><IMG height=9 94 src="<%=path%>/images/jiao.gif" width=9> 95 td> 96 tr> 97 <tr> 98 <td vAlign=top align=right width=743 height=452> 99 <table cellSpacing=0 cellPadding=0 width=556 border=0> 100 101 <tbody> 102 <tr> 103 <td vAligh=bottom width=548 height=27><IMG height=10 104 src="<%=path%>/images/jt2.gif" width=10> <span 105 class="1bt">用户登录span> 106 td> 107 <td width=8 rowSpan=3> td> 108 tr> 109 <tr> 110 <td bgColor="#ffffff" height=22>td> 111 tr> 112 <tr> 113 <td class=unnamed1 vAligh=top height=9> 114 <table width="99%" border=0 cellPadding=4 cellSpacing=1 115 bgColor="#0867b3"> 116 <tbody> 117 <TR bgColor=#ffffff height=20> 118 <TD width=14% noWrap class="STYLE7">用户名TD> 119 <TD width=24% valign="top" noWrap><INPUT class=text2 120 maxLength=20 size=18 name="username" minLength="1"> 121 TD> 122 <TD width=62% noWrap><span class="STYLE7">必须填写!span> 123 TD> 124 TR> 125 126 <TR bgColor=#ffffff height=20> 127 <TD height="2" noWrap><span class="STYLE7">密码 span> 128 TD> 129 <TD height="2" valign="top" noWrap><INPUT 130 type="password" class=text2 maxLength=20 size=18 131 name="password" minLength="1"> 132 TD> 133 <TD height="2" noWrap><span class="STYLE7">必须填写!span> <br> 134 TD> 135 TR> 136 tbody> 137 table><br> 138 tr> 139 <TR> 140 <TD height=20 align="center"><a 141 href="javascript:dosubmit();"> <img 142 src="<%=path%>/images/hh2.jpg" name="Image8" width="60" 143 height="22" border="0">a> <a 144 href="<%=path%>/register"><img 145 src="<%=path%>/images/hh1.jpg" name="Image9" width="60" 146 height="22" border="0"> a> 147 TD> 148 <TD>TD> 149 TR> 150 tbody> 151 table> 152 td> 153 <TD width=9 background="<%=path%>/images/s-1.gif">TD> 154 tr> 155 tbody> 156 table> 157 form> 158 body> 159 html>
注册页面:pass.jsp
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8" %> 2 <% 3 String path = request.getContextPath(); 4 %> 5 6 DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 7 <html> 8 <head> 9 <title>后台管理系统title> 10 <meta http-equiv=Content-Type content="text/html; charset=utf-8"> 11 12 <meta http-equiv="pragma" content="no-cache"> 13 <meta http-equiv="cache-control" content="no-cache"> 14 <meta http-equiv="expires" content="0"> 15 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 16 <meta http-equiv="description" content="This is my page"> 17 <style type="text/css"> 18 .neon { 19 FILTER: glow(color = #002E60, strength = 3) 20 } 21 22 DIV { 23 WIDTH: 70px 24 } 25 26 BODY { 27 MARGIN: 0px 28 } 29 30 BODY { 31 MARGIN-TOP: 0px; 32 SCROLLBAR-FACE-COLOR: #005fc5; 33 FONT-SIZE: 12px; 34 BACKGROUND: #ffffff; 35 SCROLLBAR-HIGHLIGHT-COLOR: #799ae1; 36 SCROLLBAR-SHADOW-COLOR: #799ae1; 37 SCROLLBAR-3DLIGHT-COLOR: #005fc5; 38 SCROLLBAR-ARROW-COLOR: #ffffff; 39 SCROLLBAR-TRACK-COLOR: #aabfec; 40 SCROLLBAR-DARKSHADOW-COLOR: #799ae1 41 } 42 STYLE> 43 <LINK href="<%=path%>/images/duan_1.css" type=text/css rel=stylesheet> 44 <META content="MSHTML 6.00.2800.1106" name=GENERATOR> 45 <style type="text/css"> 46 .style6 { 47 COLOR: #0000ff 48 } 49 50 .STYLE7 { 51 COLOR: #003366; 52 font-size: 12px; 53 } 54 style> 55 <script type="text/javascript"> 56 function dosubmit() { 57 var th = document.form1; 58 if (th.username.value == "") { 59 alert("用户名不能为空"); 60 th.username.focus(); 61 return; 62 } 63 if (th.realname.value == "") { 64 alert("姓名 不能为空"); 65 th.realname.focus(); 66 return; 67 } 68 69 if (th.password.value == "") { 70 alert("密码不能为空"); 71 th.password.focus(); 72 return; 73 } 74 if ((th.password.value).length<6) { 75 alert("密码长度小于6安全等级太低"); 76 th.password.focus(); 77 return; 78 } 79 80 if (th.password.value != th.pswds.value) { 81 alert("两次密码输入不同"); 82 th.password.focus(); 83 return; 84 } 85 86 th.action="<%=path%>/add" 87 th.submit(); 88 } 89 script> 90 head> 91 <h1>${message}h1> 92 <body bgColor=#ffffff 93 onload="MM_preloadImages('<%=path%>/images/ok_2.jpg', '<%=path%>/images/fh_2.jpg')"> 94 <form action="./add" name="form1" method="Post"> 95 <table height=470 cellSpacing=0 cellPadding=0 width=580 aligen=center 96 border=0> 97 <tbody> 98 <tr> 99 <td colSpan=3 height=9 /> 100 tr> 101 <tr> 102 <td vAlign=top width=8 background="<%=path%>/images/dhpddw.gif" 103 rowSpan=2> 104 td> 105 <td background="<%=path%>/images/h-1.gif" height=9>td> 106 <td width=9 height=9><IMG height=9 107 src="<%=path%>/images/jiao.gif" width=9> 108 td> 109 tr> 110 <tr> 111 <td vAlign=top align=right width=743 height=452> 112 <table cellSpacing=0 cellPadding=0 width=556 border=0> 113 114 <tbody> 115 <tr> 116 <td vAligh=bottom width=548 height=27><IMG height=10 117 src="<%=path%>/images/jt2.gif" width=10> <span 118 class="1bt">用户注册span> 119 td> 120 <td width=8 rowSpan=3> td> 121 tr> 122 <tr> 123 <td bgColor="#ffffff" height=22>td> 124 tr> 125 <tr> 126 <td class=unnamed1 vAligh=top height=9> 127 <table width="99%" border=0 cellPadding=4 cellSpacing=1 128 bgColor="#0867b3"> 129 <tbody> 130 <TR bgColor=#ffffff height=20> 131 <TD width=14% noWrap class="STYLE7">用户名TD> 132 <TD width=24% valign="top" noWrap><INPUT class=text2 133 maxLength=20 size=18 name="username" minLength="1"> 134 TD> 135 <TD width=62% noWrap><span class="STYLE7">必须填写!span> 136 TD> 137 TR> 138 <TR bgColor=#ffffff height=20> 139 <TD height="4" noWrap><span class="STYLE7">姓 名span> 140 TD> 141 <TD height="4" valign="top" noWrap><INPUT class=text2 142 maxLength=20 size=18 name="realname" minLength="1"> 143 TD> 144 <TD height="4" noWrap><span class="STYLE7">必须填写!span> 145 TD> 146 TR> 147 <TR bgColor=#ffffff height=20> 148 <TD height="3" noWrap><span class="STYLE7">密码 span> 149 TD> 150 <TD height="2" valign="top" noWrap><INPUT 151 type="password" class=text2 maxLength=20 size=18 152 name="password" minLength="1"> 153 TD> 154 <TD height="2" noWrap><span class="STYLE7">必须填写!span> <br> 155 TD> 156 TR> 157 <TR bgColor=#ffffff height=20> 158 <TD height="2" noWrap style="width: 55px; "><span class="STYLE7">确认密码 span> 159 TD> 160 <TD height="2" valign="top" noWrap><INPUT 161 type="password" class=text2 maxLength=20 size=18 162 name="pswds" minLength="1"> 163 TD> 164 <TD height="2" noWrap><span class="STYLE7">必须填写!span> <br> 165 TD> 166 TR> 167 tbody> 168 table><br> 169 <label>性别:label> 170 <label>男label> 171 <input type="radio" checked="true" value="男" name="sex" style="height: 14px; width: 15px; "/> 172 <label>女label> 173 <input type="radio" value="女" name="sex" style="height: 14px; width: 15px; "/> 174 tr> 175 <TR> 176 <TD height=20 align="center"><a 177 href="javascript:dosubmit();"><img 178 src="<%=path%>/images/ok_1.jpg" name="Image8" width="60" 179 height="22" border="0"> a> <a 180 href="<%=path%>/login"><img 181 src="<%=path%>/images/fh_1.jpg" name="Image9" width="60" 182 height="22" border="0"> a> 183 TD> 184 <TD>TD> 185 TR> 186 tbody> 187 table> 188 td> 189 <TD width=9 background="<%=path%>/images/s-1.gif">TD> 190 tr> 191 tbody> 192 table> 193 form> 194 body> 195 html>
返回用户信息页面:xinxi.jsp
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 2 3 DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 4 5 <html> 6 <head> 7 <title>My JSP 'xinxi.jsp' starting pagetitle> 8 9 <meta http-equiv="pragma" content="no-cache"> 10 <meta http-equiv="cache-control" content="no-cache"> 11 <meta http-equiv="expires" content="0"> 12 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 13 <meta http-equiv="description" content="This is my page"> 14 17 <script type="text/javascript"> 18 19 20 21 script> 22 head> 23 24 25 <body> 26 <% 27 String name = ""; 28 String realname = ""; 29 String pswd = ""; 30 String sex = ""; 31 if(session != null){ 32 name = (String) session.getAttribute("username"); 33 pswd = (String) session.getAttribute("password"); 34 realname = (String) session.getAttribute("realname"); 35 sex = (String) session.getAttribute("sex"); 36 //if(uname != null && !uname.equals("") && pword != null && !pword.equals("")){ 37 out.println("Input UserName: "+ name +"
"); 38 out.println("Input PassWord: "+ pswd +"
"); 39 out.println("Input realname: "+ realname +"
"); 40 out.println("Input sex: "+ sex +""); 41 42 43 } 44 45 46 %> 47 body> 48 html>
实验截图: