📄 awardsvlt.java
字号:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import myBean.AwardPC;
public class AwardSvlt extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
String stu_id = req.getParameter("stu_id");
int success = 0;
String action = req.getParameter("action");
AwardPC ad = null;
String message="";
String record_time = req.getParameter("record_time");
String levels = req.getParameter("levels");
if("new".equalsIgnoreCase(action)){
if(isTrue(req,res,stu_id,record_time,levels) && hasLogin(req,res,stu_id,record_time,levels)){
ad = doNew(req,res,stu_id,record_time,levels);
sendBean(req, res, ad, "/getAward.jsp");
}
}
if ("update".equalsIgnoreCase(action)){
//levels = req.getParameter("description");
if(isTrue(req,res,stu_id,record_time,levels)){
try{
ad = doUpdate(req,res,stu_id,record_time,levels);
sendBean(req,res,ad,"/getAward.jsp");
}
catch(SQLException e){}
}
}
if ("delete".equalsIgnoreCase(action)) {
levels = req.getParameter("code");
try{
success = doDelete(req,res,stu_id,record_time,levels);
}
catch(SQLException e){}
if (success == 0) {
doError(req, res, "无效操作,删除失败! " );
} else {
res.sendRedirect("http://localhost:8080/0903/getAward.jsp");
}
}
}
public AwardPC doNew(HttpServletRequest req,HttpServletResponse res,String stu_id,String record_time,String levels)
throws ServletException,IOException{
AwardPC ad= new AwardPC();
String info = new String(req.getParameter("info").getBytes("ISO8859_1"));
String validate = new String(req.getParameter("validate").getBytes("ISO8859_1"));
ad.setStu_id(stu_id);
ad.setLevels(levels);
ad.setRecord_time(record_time);
ad.setInfo(info);
ad.setValidate(validate);
ad.addAwardPC();
return ad;
}
public AwardPC doUpdate(HttpServletRequest req,HttpServletResponse res ,String stu_id,String record_time,String levels)
throws ServletException,IOException,SQLException {
AwardPC ad = new AwardPC();
String info = req.getParameter("info");
String validate = new String(req.getParameter("validate").getBytes("ISO8859_1"));
ad.setStu_id(stu_id);
ad.setRecord_time(record_time);
ad.setLevels(levels);
ad.setInfo(info);
ad.setValidate(validate);
ad.updateAwardPC();
return ad;
}
public int doDelete(HttpServletRequest req,HttpServletResponse res,String stu_id,String record_time,String levels)
throws ServletException,SQLException,IOException {
int num=0;
AwardPC ad=new AwardPC();
num=ad.deleteAwardPC(stu_id,record_time,levels);
return num;
}
public void sendBean(HttpServletRequest req, HttpServletResponse res,
AwardPC ad, String target)
throws ServletException, IOException {
req.setAttribute("ad", ad);
RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
rd.forward(req, res);
}
public void doError(HttpServletRequest req,
HttpServletResponse res,
String str)
throws ServletException, IOException {
req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}
public boolean hasLogin(HttpServletRequest req, HttpServletResponse res,String stu_id,String record_time,String levels)
throws ServletException, IOException{
boolean f=true;
String message="对不起,该项已经存在了!";
AwardPC ad= new AwardPC();
f= ad.hasLogin(stu_id,record_time,levels);
if(f==false){
doError(req,res,message);
}
return f;
}
public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
String stu_id,String record_time,String levels)
throws ServletException, IOException {
boolean f=true;
String message ="";
if(stu_id==null || stu_id.trim().equals("")){
f=false;
message="错误,学号不能为空!";
doError(req,res,message);
}else if(levels==null || levels.trim().equals("")){
f=false;
message="错误,奖励不能为空!";
doError(req,res,message);
}
else if(record_time==null || record_time.trim().equals("")){
f=false;
message="错误,日期必须输入!";
doError(req,res,message);
}
return f;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -