wtservlet.java
来自「一个简单的同学录」· Java 代码 · 共 112 行
JAVA
112 行
package txl.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import txl.tools.*;
import javax.servlet.RequestDispatcher;
public class WtServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public WtServlet() {
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.equals("add")){
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"));
DbBean db = new DbBean();
db.addnew(txl);
List list = db.ShowInfo();
db.close();
request.setAttribute("list1", list);
//response.sendRedirect("/txl/txllist.jsp");
System.out.println("111111");
RequestDispatcher rd = request.getRequestDispatcher("/txllist.jsp");
rd.forward(request, response);
System.out.println("222222");
}
if(mod.equals("del")){
String id = request.getParameter("id");
DbBean db = new DbBean();
db.delUser(id);
List list = db.ShowInfo();
db.close();
request.setAttribute("list1", list);
RequestDispatcher rd = request.getRequestDispatcher("/txllist.jsp");
rd.forward(request, response);
}
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("/txlmod.jsp");
rd.forward(request, response);
}
if(mod.equals("mmm")){
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"));
DbBean db = new DbBean();
db.txlMod(txl);
List list = db.ShowInfo();
db.close();
request.setAttribute("list1", list);
RequestDispatcher rd = request.getRequestDispatcher("/txllist.jsp");
rd.forward(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 {
doGet(request,response);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?