资源简介

本人博客中的代码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.xml
     文件          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.xml
     文件         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.xml
     文件        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\meta-INF\
     文件          39  2016-06-16 16:49  jspServletMyBatis\WebRoot\meta-INF\MANIFEST.MF
     文件        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个文件信息

评论

共有 条评论