4、mybatis动态sql+struts2(通配符+全局配置+分页)

1.创建userinfo.sql数据库脚本

 create table USERINFO
(
id NUMBER not null,
uname VARCHAR2(20),
password VARCHAR2(20),
age NUMBER
)
;
alter table USERINFO add primary key (ID); create sequence seq_userinfo; insert into USERINFO (id, uname, password, age)
values (seq_userinfo.nextval, 'holly', '', 18);
insert into USERINFO (id, uname, password, age)
values (seq_userinfo.nextval, '石头', '', 18);
insert into USERINFO (id, uname, password, age)
values (seq_userinfo.nextval, '朱亚楠', '', 18);
insert into USERINFO (id, uname, password, age)
values (seq_userinfo.nextval, '大嘴', '', null);
commit;

userinfo.sql

2.创建如下项目结构

4、mybatis动态sql+struts2(通配符+全局配置+分页)

4、mybatis动态sql+struts2(通配符+全局配置+分页)

3.在项目WebRoot的WEB-INF下的lib中加入如下jar文件

4.在com.entity包下创建UserInfo.java

 package com.entity;

 import com.page.Page;

 /**
* 用户信息表
* @author pc
*
*/
public class UserInfo {
private Integer id;
private String uname;
private String password;
private Page page; //分页数据封装类 public UserInfo() {
} public UserInfo(Integer id) {
this.id = id;
} public UserInfo(Page page) {
this.page = page;
} public UserInfo(String uname, String password) {
this.uname = uname;
this.password = password;
}
public UserInfo(Integer id, String uname, String password) {
this.id = id;
this.uname = uname;
this.password = password;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
} public Page getPage() {
return page;
} public void setPage(Page page) {
this.page = page;
} @Override
public String toString() {
return "UserInfo [id=" + id + ", password=" + password + ", uname="
+ uname + "]";
} }

UserInfo.java

5.在com.mapper包下创建UserInfoMapper.java映射接口

 package com.mapper;

 import java.util.List;

 import com.entity.UserInfo;

 public interface UserInfoMapper {
/**
* 根据id查询
* @param id
* @return
*/
//public UserInfo getById(int id);
/**
* 根据对象查询对象
* @param user
* @return
*/
//public UserInfo getByNamePwd(UserInfo user);
/**
* 查询所有和根据条件查询
* @return
*/
public List<UserInfo> getAllAndWhere(UserInfo user);
/**
* 添加
* @param user
* @return
*/
public Integer saveUser(UserInfo user);
/**
* 修改
* @param user
* @return
*/
public Integer updateUser(UserInfo user); /**
* 根据id删除
* @param id
* @return
*/
public Integer deleteUser(int id); /**
* 查询总记录数
* @return
*/
public Integer getTotalCount(); }

UserInfoMapper.java

6.在com.mapper包下创建UserInfoMapper.xml映射文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.mapper.UserInfoMapper">
<!-- 查询所有和根据条件查询 -->
<select id="getAllAndWhere" parameterType="User" resultType="User">
<choose>
<!-- 分页查询 -->
<when test="page!=null">
<![CDATA[
select * from
(
select rownum r,id,uname,password from userinfo
where rownum<=#{page.startrow}
)u
where u.r>#{page.endrow}
]]>
</when>
<otherwise>
select * from userinfo
<where>
<choose>
<!-- 根据用户名和密码查询 -->
<when test="uname!=null and password!=null">
and uname=#{uname} and password=#{password}
</when>
<otherwise>
<!-- 根据id查询 -->
<if test="id!=null">
and id=#{id}
</if>
</otherwise>
</choose>
</where>
</otherwise>
</choose> </select>
<!-- 修改 -->
<update id="updateUser" parameterType="User">
update userinfo set uname=#{uname},password=#{password} where id=#{id}
</update> <!-- 添加 -->
<insert id="saveUser" parameterType="User">
insert into userinfo(id,uname,password)
values(seq_userinfo.nextval,#{uname},#{password})
</insert>
<!-- 删除 -->
<delete id="deleteUser" parameterType="int">
delete from userinfo where id=#{id}
</delete>
<!-- 查询总条数 -->
<select id="getTotalCount" resultType="Integer">
select count(*) from userinfo
</select> </mapper>

UserInfoMapper.xml

7.在src下创建jdbc.properties的连接数据库的属性文件

 driver=oracle.jdbc.driver.OracleDriver
url=jdbc\:oracle\:thin\:@127.0.0.1\:1521\:orcl
username=holly
password=sys

jdbc.properties

8.在src下创建日志文件log4j.properties属性文件

 log4j.rootLogger=DEBUG, Console  

 #Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n log4j.logger.java.sql.ResultSet=INFO
log4j.logger.org.apache=INFO
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

log4j.properties

9.在src下创建mybatis的主配置文件configuration.xml

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd" >
<configuration>
<!-- 引用属性文件 -->
<properties resource="jdbc.properties"/> <!-- 定义别名 -->
<typeAliases>
<typeAlias type="com.entity.UserInfo" alias="User"/>
</typeAliases> <!-- 数据源配置 -->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<property name="url" value="${url}"/>
<property name="username" value="${username}"/>
<property name="password" value="${password}"/>
</dataSource>
</environment>
</environments>
<!-- 注册映射文件 -->
<mappers>
<mapper resource="com/mapper/UserInfoMapper.xml"/>
</mappers>
</configuration>

configuration.xml

10.在com.util包下创建获取SqlSession对象的MyBatisUtil.java工具类

 package com.util;

 import java.io.IOException;
import java.io.Reader; import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder; /**
* 获取Sqlsession工具类
* @author pc
*
*/
public class MyBatisUtil {
private static SqlSessionFactory sqlSessionFactory=null;
static{
try {
Reader reader=Resources.getResourceAsReader("configuration.xml");
sqlSessionFactory=new SqlSessionFactoryBuilder().build(reader);
} catch (IOException e) {
e.printStackTrace();
}
} public static SqlSession getSqlSession(boolean isCommit){
return sqlSessionFactory.openSession(isCommit);
} }

MyBatisUtil.java

11.在com.mapper.impl包下创建UserInfoMapperImpl.java映射接口实现类

 package com.mapper.impl;

 import java.util.List;

 import org.apache.ibatis.session.SqlSession;

 import com.entity.UserInfo;
import com.mapper.UserInfoMapper;
import com.util.MyBatisUtil; public class UserinfoMapperImpl implements UserInfoMapper {
private SqlSession sqlsession=null;
/**
* 删除
*/
public Integer deleteUser(int id) {
sqlsession=MyBatisUtil.getSqlSession(true);
UserInfoMapper mapper=sqlsession.getMapper(UserInfoMapper.class);
Integer num=mapper.deleteUser(id);
sqlsession.close();
return num;
}
/**
* 登录和各种查
*/
public List<UserInfo> getAllAndWhere(UserInfo user) {
sqlsession=MyBatisUtil.getSqlSession(false);
UserInfoMapper mapper=sqlsession.getMapper(UserInfoMapper.class);
List<UserInfo> list=mapper.getAllAndWhere(user);
sqlsession.close();
return list;
}
/**
* 添加
*/
public Integer saveUser(UserInfo user) {
sqlsession=MyBatisUtil.getSqlSession(true);
UserInfoMapper mapper=sqlsession.getMapper(UserInfoMapper.class);
Integer num=mapper.saveUser(user);
sqlsession.close();
return num;
}
/**
* 修改
*/
public Integer updateUser(UserInfo user) {
sqlsession=MyBatisUtil.getSqlSession(true);
UserInfoMapper mapper=sqlsession.getMapper(UserInfoMapper.class);
Integer num=mapper.updateUser(user);
sqlsession.close();
return num;
}
/**
* 查询总条数
*/
public Integer getTotalCount() {
sqlsession=MyBatisUtil.getSqlSession(true);
UserInfoMapper mapper=sqlsession.getMapper(UserInfoMapper.class);
Integer num=mapper.getTotalCount();
sqlsession.close();
return num;
} }

UserinfoMapperImpl.java

12.在com.page包下创建Page.java分页数据封装类

 package com.page;

 public class Page {
private Integer pagesize; // 页面大小
private Integer pageno; // 当前页
private Integer totalcount; // 总记录数
private Integer totalpage;
private Integer startrow; // 开始行
private Integer endrow; // 结束行 public Page() {
} /*public Page(Integer totalcount) {
this.setTotalpage(totalcount);
}*/ public Page(Integer pagesize, Integer pageno,Integer totalcount) {
this.pageno=pageno;
this.pagesize=pagesize;
this.endrow = (pageno - 1) * pagesize;
this.startrow = pageno * pagesize;
this.setTotalpage(totalcount);
} public Integer getPagesize() {
return pagesize;
} public void setPagesize(Integer pagesize) { this.pagesize = pagesize; } public Integer getPageno() {
return pageno;
} public void setPageno(Integer pageno) { this.pageno = pageno; } public Integer getTotalcount() {
return totalcount;
} public void setTotalcount(Integer totalcount) {
this.totalcount = totalcount;
} public Integer getTotalpage() {
return totalpage;
} public void setTotalpage(Integer totalcount) {
this.setTotalcount(totalcount);
this.totalpage = totalcount % pagesize == 0 ? totalcount / pagesize
: totalcount / pagesize + 1; } public Integer getStartrow() {
return startrow;
} public void setStartrow(Integer startrow) {
this.startrow = startrow;
} public Integer getEndrow() {
return endrow;
} public void setEndrow(Integer endrow) {
this.endrow = endrow;
} @Override
public String toString() {
return "Page [endrow=" + endrow + ", pageno=" + pageno + ", pagesize="
+ pagesize + ", startrow=" + startrow + ", totalcount="
+ totalcount + ", totalpage=" + totalpage + "]";
} }

Page.java

13.在com.service包下创建UserInfoService.java业务接口

package com.service;

import java.util.List;

import com.entity.UserInfo;

/**
* 服务层接口
* @author pc
*
*/
public interface UserInfoService {
/**
* 根据id查询
* @param id
* @return
*/
//public UserInfo getById(int id);
/**
* 根据对象查询对象
* @param user
* @return
*/
//public UserInfo getByNamePwd(UserInfo user);
/**
* 查询所有和根据条件查询
* @return
*/
public List<UserInfo> getAllAndWhere(UserInfo user);
/**
* 添加
* @param user
* @return
*/
public Integer saveUser(UserInfo user);
/**
* 修改
* @param user
* @return
*/
public Integer updateUser(UserInfo user); /**
* 根据id删除
* @param id
* @return
*/
public Integer deleteUser(int id); /**
* 查询总记录数
* @return
*/
public Integer getTotalCount(); }

UserInfoService.java

14.在com.service.impl包下创建UserInfoServiceImpl.java业务接口实现类

 package com.service.impl;

 import java.util.List;

 import com.entity.UserInfo;
import com.mapper.UserInfoMapper;
import com.mapper.impl.UserinfoMapperImpl;
import com.service.UserInfoService; public class UserInfoServiceImpl implements UserInfoService {
UserInfoMapper mapper=new UserinfoMapperImpl(); public Integer deleteUser(int id) {
return mapper.deleteUser(id);
} public Integer updateUser(UserInfo user) {
return mapper.updateUser(user);
} public List<UserInfo> getAllAndWhere(UserInfo user) {
return mapper.getAllAndWhere(user);
} public Integer saveUser(UserInfo user) {
return mapper.saveUser(user);
} public Integer getTotalCount() {
// TODO Auto-generated method stub
return mapper.getTotalCount();
} }

UserInfoServiceImpl.java

15.在com.action包下创建Struts2的控制器类UserInfoAction.java

 package com.action;

 import java.util.List;

 import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.entity.UserInfo;
import com.opensymphony.xwork2.ActionSupport;
import com.page.Page;
import com.service.UserInfoService;
import com.service.impl.UserInfoServiceImpl;
/**
* //1.获取request,session的方法1:解耦方式 ActionContext ac=
* ActionContext.getContext(); //1.1将数据放给request对象集合
* Map<String, Object> requestMap=(Map<String, Object>)
* ac.get("request"); //就相当于setAttribute(key,value);
* requestMap.put("list", "list");
*
* //1.2.获取session对象集合 Map<String, Object>
* sessionMap=ac.getSession(); sessionMap.put("uname",
* loginlist.get(0).getUname());
*/
public class UserInfoAction extends ActionSupport { UserInfoService service = new UserInfoServiceImpl();
/**
* 该对象接受表单的值(代理对象通过setter和getter)
*/
private UserInfo user;
/**
* 封装page对象的
*/
private Page page; /**
* 1.登录
*
* @return
*/
public String login() {
if (user!= null) {
System.out.println("参数已经接到");
// 业务处理
List<UserInfo> loginlist = service.getAllAndWhere(user);
UserInfo useinfo=loginlist.get(0);
if (useinfo != null) {
System.out.println("登录成功");
// 2.获取request,session的方法2:耦合方式
// 2.1获取request对象
HttpServletRequest request = ServletActionContext
.getRequest();
// request.setAttribute("list", "list");
// 2.2获取session对象
HttpSession session = request.getSession();
session.setAttribute("uname", useinfo.getUname()); return SUCCESS; } else {
System.out.println("登录失败");
return ERROR;
}
} else {
System.out.println("参数没有接到");
return ERROR;
} } /**
* 2.查询所有
* @return
*/
public String findAll(){
HttpServletRequest request=ServletActionContext.getRequest(); //查单条
Integer totalCount=service.getTotalCount();
Integer pageNo=1;
if(page!=null){
pageNo=page.getPageno();
} page=new Page(2, pageNo, totalCount);
System.out.println("page:"+page);
//如果page对象为空=查询所有,如果page对象不为空=分页查询
UserInfo u=new UserInfo(page);
System.out.println("分页对象"+page);
List<UserInfo> list=service.getAllAndWhere(u);
if(list!=null){
System.out.println("查询所有,查到了...");
request.setAttribute("list", list);
request.setAttribute("page", page);
return SUCCESS;
}else{
System.out.println("查询所有,没有查到...");
return ERROR;
}
}
/**
*3. 根据id查询
* @return
*/
public String findById(){
Integer id=user.getId();
if(id!=null){
System.out.println("id接到了.."); List<UserInfo> list=service.getAllAndWhere(user);
UserInfo userinfo=list.get(0);
if(userinfo!=null){
System.out.println("根据id查到了");
HttpServletRequest request=ServletActionContext.getRequest();
request.setAttribute("upuser", userinfo);
return SUCCESS; }else{
System.out.println("根据id没有查到");
return ERROR;
}
}else{
System.out.println("id没有接到...");
return ERROR;
} }
/**
* 4.注册
* @return
*/
public String register(){
if(user!=null){
System.out.println("参数接到了..");
Integer num=service.saveUser(user);
if(num>0){
System.out.println("注册成功...");
return SUCCESS;
}else{
System.out.println("注册失败...");
return ERROR;
}
}else{
System.out.println("参数没有接到.."); return ERROR;
}
}
/**
* 5.修改
* @return
*/
public String update(){
if(user!=null){
System.out.println("参数接到了..");
Integer num=service.updateUser(user);
if(num>0){
System.out.println("修改成功");
return SUCCESS;
}else{
System.out.println("修改失败");
return ERROR;
}
}else{
System.out.println("参数没有接到..");
return ERROR;
}
} /**
* 6.删除
* @return
*/
public String delete(){
if(user.getId()!=null){
System.out.println("id接到了");
int num=service.deleteUser(user.getId());
if(num>0){
System.out.println("删除成功");
return SUCCESS;
}else{
System.out.println("删除失败");
return ERROR;
}
}else{
System.out.println("id没有接到");
return ERROR;
}
}
public UserInfo getUser() {
return user;
} public void setUser(UserInfo user) {
this.user = user;
} public Page getPage() {
return page;
} public void setPage(Page page) {
this.page = page;
} }

UserInfoAction.java

16.在src下创建struts.xml文件

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "struts-2.1.7.dtd" >
<struts>
<!-- 处理中文乱码 -->
<constant name="struts.i18n.encoding" value="UTF-8"/> <package name="default" namespace="/" extends="struts-default"> <!--
配置全局action节点的result,reuslt是公用的,
全局配置不能和默认配置一起使用
-->
<global-results>
<result name="error">error.jsp</result>
</global-results> <!-- 登录,修改,删除,注册 形成一个动态调用=通配符使用 -->
<action name="*" class="com.action.UserInfoAction" method="{1}">
<result name="success" type="redirectAction">findAll</result>
</action> <!-- 查询所有 -->
<action name="findAll" class="com.action.UserInfoAction" method="findAll">
<result name="success">index.jsp</result>
</action> <!-- 查单条 -->
<action name="findById" class="com.action.UserInfoAction" method="findById">
<result name="success">update.jsp</result>
</action> <!-- 登陆
<action name="login" class="com.action.UserInfoAction" method="login">
<result name="success" type="redirectAction">findAll</result>
</action>
--> <!-- 修改
<action name="update" class="com.action.UserInfoAction" method="update">
<result name="success" type="redirectAction">findAll</result>
</action>
-->
<!-- 添加
<action name="register" class="com.action.UserInfoAction" method="register">
<result name="success">login.jsp</result>
</action>
--> <!-- 删除
<action name="delete" class="com.action.UserInfoAction" method="delete">
<result name="success" type="redirectAction">findAll</result>
</action>
--> </package>
</struts>

struts.xml

17.编辑WebRoot下WEB-INF下的web.xml文件

 <?xml version="1.0" encoding="UTF-8"?>
<web-app version="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">
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<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>*.action</url-pattern>
</filter-mapping>
</web-app>

web.xml

18.在WebRoot下创建js文件夹加入jquery-1.8.3.js文件

19.在WebRoot下创建login.jsp登录页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset style="width:300px">
<legend>登录</legend>
<form action="login.action" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="user.uname"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="user.password"/></td>
</tr>
<tr>
<td><input type="submit" value="登录"/></td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

login.jsp

20.在WebRoot下创建index.jsp首页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
$("tr:odd").css("background-color","#ccc");
});
</script>
</head> <body>
<center>
<h1>欢迎${uname}登录成功!</h1>
<table>
<tr><td colspan="2"><a href="register.jsp">注册</a></td></tr>
<tr><td>编号</td><td>姓名</td><td>密码</td><td>操作</td></tr>
<c:forEach var="i" items="${list}">
<tr><td>${i.id}</td><td>${i.uname}</td><td>${i.password}</td>
<td><a href="findById.action?user.id=${i.id}">修改</a>&nbsp;|&nbsp;<a href="delete.action?user.id=${i.id}">删除</a></td></tr>
</c:forEach>
</table>
当前第${page.pageno}/${page.totalpage }页 &nbsp;&nbsp;
<a href="findAll.action?page.pageno=1">首页</a> &nbsp;&nbsp;
<c:choose>
<c:when test="${page.pageno > 1}">
<a href="findAll.action?page.pageno=${page.pageno-1}">上一页</a> &nbsp;&nbsp; </c:when>
<c:otherwise>
<a href="javascript:alert('已经是第一页!');">上一页</a> &nbsp;&nbsp;
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${page.pageno<page.totalpage}">
<a href="findAll.action?page.pageno=${page.pageno+1}">下一页</a> &nbsp;&nbsp; </c:when>
<c:otherwise>
<a href="javascript:alert('已经是最后一页!');">上一页</a> &nbsp;&nbsp; </c:otherwise>
</c:choose> <a href="findAll.action?page.pageno=${page.totalpage}">末页</a>
</center>
</body>
</html>

index.jsp

21.在WebRoot下创建register.jsp注册页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset style="width:300px">
<legend>注册</legend>
<form action="register.action" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="user.uname"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="user.password"/></td>
</tr>
<tr>
<td><input type="submit" value="注册"/></td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

register.jsp

22.在WebRoot下创建update.jsp修改页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
<center>
<fieldset style="width:300px">
<legend>修改用户信息</legend>
<form action="update.action?user.id=${upuser.id}" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="user.uname" value="${upuser.uname}"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="user.password" value="${upuser.password}"/></td>
</tr>
<tr>
<td><input type="submit" value="注册"/></td>
</tr>
</table>
</form>
</fieldset>
</center>
</body>
</html>

update.jsp

23.在error.jsp下创建error.jsp错误页面

 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head> <body>
业务处理失败!!
</body>
</html>

error.jsp

24.运行结果如下

4、mybatis动态sql+struts2(通配符+全局配置+分页)

4、mybatis动态sql+struts2(通配符+全局配置+分页)4、mybatis动态sql+struts2(通配符+全局配置+分页)4、mybatis动态sql+struts2(通配符+全局配置+分页)4、mybatis动态sql+struts2(通配符+全局配置+分页)4、mybatis动态sql+struts2(通配符+全局配置+分页)4、mybatis动态sql+struts2(通配符+全局配置+分页)

上一篇:Sptringboot 添加子项目


下一篇:C#判断网站运行状态是否正常