资源简介
本人博客中的代码Jsp+Servlet+MyBatis完成分页查询 http://blog.csdn.net/japanstudylang/article/details/51700874

代码片段和文件信息
package com.yw.servlet;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import com.yw.test12.Condition;
public class StudentServlet extends HttpServlet
{
/**
* The doGet method of the servlet.
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException
{
doPost(request response);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form has its tag value method equals to post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException
{
response.setCharacterEncoding(“utf-8“);
String spage = request.getParameter(“page“);
System.out.println(“spage=“ + spage);
int page = 1;
if (spage != null)
{
try
{
page = Integer.parseInt(spage);
if(page<1)
{
throw new Exception();
}
}
catch (Exception e)
{
request.setAttribute(“error“ “page不合法“);
request.getRequestDispatcher(“student.jsp“).forward(request response);
}
}
String resource = “com/yw/test12/mybatis-config.xml“;
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession session = sqlSessionFactory.openSession(false);
try
{
System.out.println(“=====动态SQL======“);
Condition s1 = new Condition();
// s1.setName(“%a%“);
// s1.setName(““);
s1.setStart((page - 1) * 3);// /////////////
s1.setCount(3);
List user = session.selectList(“com.yw.test12.StudentMapper.findStudent“ s1);
System.out.println(user);
// ArrayList s=(ArrayList)db.query(“select * from user limit “+ (page-1)*3+“3“);
System.out.println(“s=“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-06-17 16:39 jspServletMyBatis\
文件 1093 2016-06-16 16:49 jspServletMyBatis\.classpath
文件 1342 2016-06-17 15:33 jspServletMyBatis\.project
目录 0 2016-06-17 16:39 jspServletMyBatis\.settings\
文件 522 2016-06-16 16:49 jspServletMyBatis\.settings\.jsdtscope
文件 364 2016-06-16 16:49 jspServletMyBatis\.settings\org.eclipse.jdt.core.prefs
文件 512 2016-06-16 16:49 jspServletMyBatis\.settings\org.eclipse.wst.common.component
文件 414 2016-06-16 16:49 jspServletMyBatis\.settings\org.eclipse.wst.common.project.facet.core.xm
文件 49 2016-06-16 16:49 jspServletMyBatis\.settings\org.eclipse.wst.jsdt.ui.superType.container
文件 6 2016-06-16 16:49 jspServletMyBatis\.settings\org.eclipse.wst.jsdt.ui.superType.name
目录 0 2016-06-17 16:39 jspServletMyBatis\src\
目录 0 2016-06-17 16:39 jspServletMyBatis\src\com\
目录 0 2016-06-17 16:39 jspServletMyBatis\src\com\yw\
目录 0 2016-06-17 16:39 jspServletMyBatis\src\com\yw\servlet\
文件 3678 2016-06-17 16:34 jspServletMyBatis\src\com\yw\servlet\StudentServlet.java
目录 0 2016-06-17 16:39 jspServletMyBatis\src\com\yw\test12\
文件 583 2016-06-16 15:58 jspServletMyBatis\src\com\yw\test12\Condition.java
文件 809 2016-06-16 15:39 jspServletMyBatis\src\com\yw\test12\mybatis-config.xm
文件 748 2016-06-16 15:39 jspServletMyBatis\src\com\yw\test12\Student.java
文件 581 2016-06-17 16:24 jspServletMyBatis\src\com\yw\test12\StudentMapper.xm
文件 1020 2016-06-16 16:19 jspServletMyBatis\src\com\yw\test12\Test01.java
文件 96 2016-06-14 17:00 jspServletMyBatis\src\config.properties
目录 0 2016-06-17 16:39 jspServletMyBatis\WebRoot\
文件 829 2016-06-16 16:49 jspServletMyBatis\WebRoot\index.jsp
目录 0 2016-06-17 16:39 jspServletMyBatis\WebRoot\me
文件 39 2016-06-16 16:49 jspServletMyBatis\WebRoot\me
文件 1741 2016-06-17 16:15 jspServletMyBatis\WebRoot\student.jsp
目录 0 2016-06-17 16:39 jspServletMyBatis\WebRoot\WEB-INF\
目录 0 2016-06-17 16:39 jspServletMyBatis\WebRoot\WEB-INF\classes\
目录 0 2016-06-17 16:39 jspServletMyBatis\WebRoot\WEB-INF\classes\com\
目录 0 2016-06-17 16:39 jspServletMyBatis\WebRoot\WEB-INF\classes\com\yw\
............此处省略13个文件信息
相关资源
- JSP,SQL,MVC的选课系统
- 基于JSP的学生宿舍管理系统(源码 数
- JSP选课管理系统
- mysql jsp网站源码下载
- JSP做的化妆品商城
- Jsp购物车实例
- 基于JSP的校友信息管理系统(添加数
- 基于jsp的bbs论坛 非常详细
- java Servlet投票实例
- jsp oracle通讯录
- JSP学生信息管理系统 Mysql数据库
- 使用jsp servlet做的投票系统
- JSP登陆验证 实现JSP用户名 密码 验
- jsp基于servlet 图书馆管理系统
- jsp学生成绩管理系统.rar
- 在线考试系统源代码(jsp)
- 超级好的纯jsp写的聊天室
- JSP 网上购物网页项目
- JSP+mysql新闻发布系统.rar
- jsp 学生信息管理系统设计与实现
- jsp与SQL Server数据库实现的客户注册登
- 简易教学管理系统(jsp spring struts h
- 学生信息管理系统 JSP MySQL
- jsp ajax 三级联动菜单
- jsp新闻公告与最新消息系统(具备添
- JSP课程设计-留言本 jsp mysql tomcat实现
- jsp 做的 班级管理网站
- jsp 统计在线人数利用HttpSessionListene
- jsp mysql tomcat学生信息管理系统
- jsp成绩管理系统jsp servlet javabean
评论
共有 条评论