?? awardpcsvlt.java
字號(hào):
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import myBean.awardPC;
public class AwardPCSvlt 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, "/admin.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,"/admin.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, "無(wú)效操作,刪除失敗! " );
} else {
res.sendRedirect("http://localhost:8080/0903/admin.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="對(duì)不起,該項(xiàng)已經(jīng)存在了!";
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="錯(cuò)誤,學(xué)號(hào)不能為空!";
doError(req,res,message);
}else if(levels==null || levels.trim().equals("")){
f=false;
message="錯(cuò)誤,獎(jiǎng)勵(lì)不能為空!";
doError(req,res,message);
}
else if(record_time==null || record_time.trim().equals("")){
f=false;
message="錯(cuò)誤,日期必須輸入!";
doError(req,res,message);
}
return f;
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -