资源简介
本人博客中的代码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+mysql系统+论文.rar
- 非常实用的jsp技术课件
- JSP+JDBC实现登录注册
- 超市销售管理
- java jsp教师档案管理系统 源代码
- JSP网页模板
- java+jsp毕业设计开发物流管理系统
- 用servlet做出来的Javaweb项目:图书管理
- jsp网上药店管理系统源码
- javaweb超市进销系统
- 基于java的SSM学生选课系统
- spring + spring mvc + mybatis SSM整合版+My
- 使用spring+springmvc+mybatis搭建项目需要
- 基于JSP的校园交易平台
- JSP程序设计书本源代码(第2版)
- JavaBean+Jsp+Servlet 用户注册登陆及增删
- jsp版酒店管理系统
- 在线投票系统 jsp 网页制作
- jsp新闻信息发布系统
- JSP中文开发文档 API CHM格式
- 非常全面的一个j2ee教程经过整理,适
- jsp+mysql+mvc在线点餐系统
- 网上考试报名系统设计源代码
- 网上书店完整源代码JSP+SQL+TOMCAT
- struts1+jsp登录注册全部代码 连接sqls
- 基于java的简单BBS论坛
- jsp 物流信息管理系统
- JSP课程设计——学习论坛网站
- BBS论坛使用jsp技术源代码
- 一个很好的论坛系统jsp+mysql
评论
共有 条评论