📄 myservlet.java
字号:
package txl.servlet;
import txl.tools.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
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.jspsmart.upload.*;
public class MyServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public MyServlet() {
super();
}
/**
* 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 {
String mod = request.getParameter("mod");
if(mod ==null){
RequestDispatcher rd = request.getRequestDispatcher("/tongxun/add.jsp");
rd.forward(request, response);
}else if(mod.equals("add")){
String rand = (String)request.getSession().getAttribute("rand");
String input = request.getParameter("yanzheng");
if(!rand.equals(input)){
request.setAttribute("error", "false");
RequestDispatcher rd = request.getRequestDispatcher("/tongxun/add.jsp");
rd.forward(request, response);
return;
}
TxlUserBean txl = getTxl(request);
DbBean db = new DbBean();
db.addnew(txl);
db.close();
list(request,response);
}else if(mod.equals("del")){
String id = request.getParameter("id");
DbBean db = new DbBean();
db.delUser(id);
db.close();
list(request,response);
}else if(mod.equals("med")){
String id = request.getParameter("id");
DbBean db = new DbBean();
TxlUserBean txl = new TxlUserBean();
txl = db.listUser(id);
db.close();
request.setAttribute("txlmd", txl);
RequestDispatcher rd = request.getRequestDispatcher("/tongxun/txlmod.jsp");
rd.forward(request, response);
}else if(mod.equals("mmm")){
TxlUserBean txl = getTxl(request);
DbBean db = new DbBean();
db.txlMod(txl);
db.close();
list(request,response);
}else if(mod.equals("list")){
list(request,response);
}
}
public void list(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String curPage = request.getParameter("jumpPage");
PageBean pagebean = new PageBean();
if(curPage == null){
pagebean.setCurPage(1);
}else{
pagebean.setCurPage(Integer.parseInt(curPage));
}
pagebean.setRowsPerPage(10);
DbBean db = new DbBean();
pagebean = db.ShowInfo(pagebean);
db.close();
request.setAttribute("list1", pagebean);
RequestDispatcher rd = request.getRequestDispatcher("/tongxun/txllist.jsp");
rd.forward(request, response);
}
public TxlUserBean getTxl(HttpServletRequest request)
throws ServletException, IOException {
TxlUserBean txl = new TxlUserBean();
txl.setName(request.getParameter("name"));
txl.setDz(request.getParameter("dz"));
txl.setDh(request.getParameter("dh"));
txl.setOicq(request.getParameter("oicq"));
txl.setYb(request.getParameter("yb"));
txl.setId(request.getParameter("id"));
txl.setUid(request.getParameter("uid"));
return txl;
}
/**
* 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 {
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -