⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apcsvlt.java

📁 采用基于B/S结构进行开发学生管理信息系统,本系统采用Servlet+Jsp+JavaBean+MySQL 的设计方式
💻 JAVA
字号:
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import myBean.APC;
import myBeans.SQLBean;

public class APCSvlt extends HttpServlet{
	
public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
          	
    String code =req.getParameter("code");
    int success = 0;
    String action = req.getParameter("action");
    APC apc = null;
    String message="",description="";
    
    if ("new".equalsIgnoreCase(action)) {
    	
      description=new String(req.getParameter("description").getBytes("ISO8859_1"));
      
      if(isTrue(req,res,code,description) && hasLogin(req,res,code,description)){
          apc = doNew(req,res,code,description);
          sendBean(req, res, apc, "/getAPC.jsp");
        }
    }  
    
    if ("update".equalsIgnoreCase(action)) {
        description=new String(req.getParameter("description").getBytes("ISO8859_1"));                   
        if(isTrue(req,res,code,description)&& hasLogin(req,res,"0",description)){
    	    try{		
     	       apc = doUpdate(req,res,code,description);
     	       sendBean(req,res,apc,"/getAPC.jsp");
     	    }
     	  catch(SQLException e){} 
     	 }
    }
			   
    if ("delete".equalsIgnoreCase(action)) {
      if(isDel(req,res,code)){
  	  try{			
      	  success = doDelete(code);	
      	    }
      	    catch(SQLException e){}				
    	 if (success != 1) {
    		 doError(req, res, "APCSvlt: Delete unsuccessful. Rows affected: " + success);
    	 } else {
    		 res.sendRedirect("http://localhost:8080/0903/getAPC.jsp");
    	 } 
    	} 
    }
    }
       
     public APC doNew(HttpServletRequest req,HttpServletResponse res,String code,String description)                         
                throws ServletException,IOException{                     	
      APC apc= new APC();
      
      apc.setCode(code);
      apc.setDescription(description);
      apc.addAPC();
      return apc;                	
                           	
   	}
                           	
                           	
      public APC doUpdate(HttpServletRequest req,HttpServletResponse res ,String code,String description)
                           throws ServletException,IOException,SQLException {                      	 
        APC apc = new APC();
         apc.updateAPC(code,description);
		    return  apc;
      }
  
    public int doDelete(String code) throws SQLException {
  	  int num=0;
      APC apc=new APC();
      num= apc.deleteAPC(code);
    
     return num;
  }
  
  public void sendBean(HttpServletRequest req, HttpServletResponse res,
                       APC apc, String target)
                       throws ServletException, IOException {
    req.setAttribute(" apc",  apc);
    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 code,String description)
  throws ServletException, IOException{
  	boolean f=true;
  	String message="对不起,该项已经被注册过了!";
  	APC  apc= new APC();
  	if(apc.hasLogin(code,description)==true){
  		f=false;
  	  doError(req,res,message);	
  		}
  		return f;
  	}
  	
  	
  public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
                        String code,String description)
                        throws ServletException, IOException {
   boolean f=true;                     	
   String message ="";
   if(code==null || code.equals(""))  {
   	f=false;
   	message="错误,代号不能为空!";
   	doError(req,res,message);	}
   
   else if(description==null || description.equals(""))  {
   	f=false;
   	message="描述不能为空,请重新填写!";
   	doError(req,res,message);	}
  	
     return f;
     
  }
  
  public boolean isDel(HttpServletRequest req,HttpServletResponse res ,String code)
                           throws ServletException,IOException{
                           
     String table="";boolean f = true;
  	if(code.startsWith("A"))
  		table = "award";
  	else if(code.startsWith("P"))
  	  table = "punishment";
  	else
  	  table = "change"; 
 	  SQLBean db = new SQLBean();
  	String sql = "select * from "+table+" where LEVELS='"+code+"'";
  	
  	try{
  	   ResultSet rs = db.executeQuery(sql); 
  	   if(rs==null); 	   
  	   else if(rs.next()){  
  		     f = false;
           doError(req,res,"有文件使用该项,不能删除!"); 
         } 
      }catch(SQLException e){e.getMessage();} 
      
    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 + -