有谁能帮我解决下这些代码什么意思吗?急9
发布网友
发布时间:2023-11-20 03:01
我来回答
共1个回答
热心网友
时间:2024-12-04 21:00
package com.action;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.bean.ComBean;
import com.util.Constant;
public class ComAction extends HttpServlet {
//这几个方法不解释了
public ComAction() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//这里定义返回的网络文件的类型
response.setContentType(Constant.CONTENTTYPE);
//这里定义定义编码类型
request.setCharacterEncoding(Constant.CHARACTERENCODING);
//获取session
HttpSession session = request.getSession();
//实例一个bean
ComBean cBean = new ComBean();
//把当前时间格式化为yyyy-MM-dd HH:mm:ss
String date2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime());
获取客户段传过来的方法参数
String method = request.getParameter("method");
//如果method参数为delgd
if(method.equals("delgd")){
//String xm = "";String xb="";String nl="";String xl="";String lx="";String jl="";String sk="";
//String id="";String nd = "";String xh="";String bj, String pwd=""; String xm=""; String xb=""; String nl="";
//获取参数
String bh = request.getParameter("bh");
//根据参数删除gd表的相应的数据
int flag = cBean.comUp("delete from gd where bh='"+bh+"'");
//删除成功
if(flag == Constant.SUCCESS){
//返回成功标志,并转向相应的页面
request.setAttribute("message", "操作成功");
request.getRequestDispatcher("gd/index.jsp").forward(request, response);
}
else {
//返回失败标志,并转向相应的页面
request.setAttribute("message", "操作失败");
request.getRequestDispatcher("gd/index.jsp").forward(request, response);
}
}
//如果method参数为addlb
else if(method.equals("addlb")){ ///update teacher
//获取type参数
String type = request.getParameter("type");
//根据type参数插入一条lb表mc字段数据
int flag = cBean.comUp("insert into lb(mc) values('"+type+"' )");
//同上
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功");
request.getRequestDispatcher("gd/lb.jsp").forward(request, response);
}
else if(flag == Constant.NAME_ERROR){
request.setAttribute("message", "操作失败");
request.getRequestDispatcher("gd/lb.jsp").forward(request, response);
}
}
//如果method参数为dellb
else if(method.equals("dellb")){ //del teacher
//获取id参数
String id = request.getParameter("id");
//根据id参数删除lb相应数据
int flag = cBean.comUp("delete from lb where id='"+id+"'");
//同上
if(flag == Constant.SUCCESS){
request.setAttribute("message", "操作成功");
request.getRequestDispatcher("gd/lb.jsp").forward(request, response);
}
else {
request.setAttribute("message", "操作失败");
request.getRequestDispatcher("gd/lb.jsp").forward(request, response);
}
}