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

📄 updatepesticideservlet.java

📁 该系统具体分为2个部分:前台和后台。 1.前台主要用于用户进行浏览和搜索
💻 JAVA
字号:
package ynuServlet;
import java.io.IOException;
import java.util.ArrayList;

import ynuBean.Pesticide;
import ynuBean.UpdatePesticideBean;
import javax.servlet.RequestDispatcher;
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 ynuBean.SearchInfoBean;

public class UpdatePesticideServlet extends HttpServlet {
	public void init()throws ServletException
    {
    	
    }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
    	sendsql(request,response);
    }
    
    public void sendsql(HttpServletRequest request, HttpServletResponse response)
    throws ServletException,IOException
    {  	  
    	HttpSession session = request.getSession();   	
    	String toJsp = "/update.jsp";
    	String way = request.getParameter("updatePestWay");
    	UpdatePesticideBean aBean = new UpdatePesticideBean();
    	
    	if(way.equals("addPest"))
    	{
    		String pid = request.getParameter("pid");
        	String pname = request.getParameter("pname");
        	String tox = request.getParameter("tox");
        	String cha = request.getParameter("cha");
        	float price = Float.parseFloat(request.getParameter("price"));
        	int qty = Integer.parseInt(request.getParameter("qty"));
    		//pid = new String(pid.getBytes("ISO-8859-1"),"UTF-8");
    		//pname = new String(pname.getBytes("ISO-8859-1"),"UTF-8");
    		//tox = new String(tox.getBytes("ISO-8859-1"),"UTF-8");
    		//cha = new String(cha.getBytes("ISO-8859-1"),"UTF-8");
            String msg = aBean.AddPesticide(pid, pname, tox, cha, price, qty);
        	
            session.setAttribute("message3", msg);
            
            toJsp = "/update.jsp";
    	}
    	else if(way.equals("EditPest"))
    	{
    		String Pid = request.getParameter("PestId");
    		Pesticide aPesticide = aBean.getPesticide(Pid);
    		session.setAttribute("PID", Pid);
    		session.setAttribute("PName", aPesticide.getPname());
    		session.setAttribute("Tox",aPesticide.gettoxicity());
    		session.setAttribute("Cha", aPesticide.getcharacter());
    		session.setAttribute("qty", aPesticide.getqty()+"");
    		session.setAttribute("Price", aPesticide.getPrice()+"");
    		session.setAttribute("Detail", aBean.getDetail());
    		toJsp = "/EditPesticide.jsp";
    	}
    	else if(way.equals("DeletePest"))
    	{
    		String Pid = request.getParameter("PestId");
    		String msg = aBean.DeletePesticide(Pid);
    		session.setAttribute("dmsg", msg);
    		toJsp = "/update.jsp";
    	}
        
    	RequestDispatcher dispatcher = request.getRequestDispatcher(toJsp);	
    	//dispatcher = request.getRequestDispatcher(toJsp);   	
    	response.setHeader("Refresh", "0.1; URL=/PesticideInfoManagement"+toJsp+"");
    	dispatcher.forward(request, response);
    }
	
    
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException
    {
        doGet(request, response);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -