📄 clientlistservlet.java
字号:
package com.eshop.servlet.manager.client;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.eshop.form.AccountForm;
import com.eshop.form.ClientSearchForm;
import com.eshop.page.ClientPage;
import com.eshop.page.PageBean;
import com.eshop.page.PageBusiness;
import com.eshop.page.ProductPage;
import com.eshop.service.AccountService;
import com.eshop.service.OrderService;
import com.eshop.service.ProductService;
import com.eshop.vo.Account;
import com.eshop.vo.Orders;
public class ClientListServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public ClientListServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* 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. <br>
*
* 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 {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html; charset=gb2312");
ClientSearchForm clientSearchForm=new ClientSearchForm();
PrintWriter out = response.getWriter();
AccountService account=new AccountService();
boolean done = false;//是否还需要构造搜索条件语句
//获得conditions参数
String conditions = (String) request.getParameter("conditions");
//如果用户不是第一次输入搜索条件,而是点击了next之类的连接,那么conditions参数不是空。
if (!"".equals(conditions) && conditions != null) {
done = true;
}
//没有conditions参数,说明是第一次输入搜索条件,然后需要构造conditions参数。
else {
String name = (String) request.getParameter("name");
String userid = (String) request.getParameter("userid");
// String city = (String) request.getParameter("city");
//String sql="";
//sql="select * from product";
//将从输入的参数是否合法
if(userid==null){
userid="";
}
if(name==null){
name="";
}
clientSearchForm.setName(name);
clientSearchForm.setUserid(userid);
if(userid==null||userid=="" && name==null||name==""){
conditions ="1=1";
}
if(userid != ""||!userid.equals(null) && !name.equals("")||!name.equals(null)){
conditions="userid like'%"+ userid + "%' and name like '%"+ name + "%' ";
}
if(userid == "" && name != ""){
conditions="name like'%"+ name + "%' ";
}
if(userid != "" && name == ""){
conditions="userid like'%"+ userid + "%' ";
}
done=true;
}
if(done){
try {
PageBusiness pb = new ClientPage();
String page = (String) request.getParameter("jumpPage");
try {
if (page.equals("") || page.equals(null))
page = "1";
} catch (Exception e) {
page = "1";
}
//读取数据的结果集
PageBean pageCtl = pb.listData(page, conditions);
Vector vector=pageCtl.getResult();
//读取当前页的值
String curPage=String.valueOf(pageCtl.curPage);
//读取最大值
String maxPage=String.valueOf(pageCtl.maxPage);
//最大行数
String maxRowCount=String.valueOf(pageCtl.maxRowCount);
//第页的行数
String rowsPerPage=String.valueOf(pageCtl.rowsPerPage);
//最大页数
//String maxPage=String.valueOf(pageCtl.countMaxPage());
//将查询结果存储到REQUEST对象中
request.setAttribute("list", vector);
//把PageBean保存到request对象中。
request.setAttribute("SearchForm",clientSearchForm);
request.setAttribute("curPage", curPage);
request.setAttribute("maxPage",maxPage);
request.setAttribute("maxRowCount", maxRowCount);
request.setAttribute("rowsPerPage", rowsPerPage);
request.setAttribute("conditions", conditions);
// request.setAttribute("page", pageCtl);
} catch (Exception e) {
out.println("发生异常:!" + e.getMessage());
out.println("<a href=" + request.getRequestURI() + ">返回</a>");
}
RequestDispatcher requestDisptcher=request.getRequestDispatcher("../manager/client/clientlist.jsp");
requestDisptcher.forward(request, response);
}
//}
}
//}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -