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

📄 saleservlet.java~19~

📁 这是本人刚刚得到的JBuilder9软件开发项目实践的源码
💻 JAVA~19~
字号:
package jxc;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.sql.*;/** * <p>Title: jxc demo</p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author cwx * @version 1.0 */public class SaleServlet extends HttpServlet {  private static final String CONTENT_TYPE = "text/html; charset=GB2312";  //Initialize global variables  public void init() throws ServletException {  }  //Process the HTTP Get request  public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    String wareID = request.getParameter("wareID");    if (wareID == null) {      wareID = "";    }    float salePrice;    try {      salePrice = Float.parseFloat(request.getParameter("salePrice"));    }    catch(Exception e) {      salePrice = 0f;    }    int saleQty;    try {      saleQty = Integer.parseInt(request.getParameter("saleQty"));    }    catch(NumberFormatException e) {      saleQty = 0;    }    String saleDate = request.getParameter("saleDate");    if (saleDate == null) {      saleDate = "";    }    /*JBuilder自动生成的代码    response.setContentType(CONTENT_TYPE);    PrintWriter out = response.getWriter();    out.println("<html>");    out.println("<head><title>SaleServlet</title></head>");    out.println("<body bgcolor=\"#ffffff\">");    out.println("<p>The servlet has received a " + request.getMethod() + ". This is the reply.</p>");    out.println("</body></html>");*/    if(SaleManager.addSale(wareID, salePrice, saleQty, saleDate)){      //转往销售结果显示界面      String wareName = "", resQty = "";      Connection conn = null;      PreparedStatement stmt = null;      ResultSet rs = null;      try{        conn = ConnectionManager.getConnection();        //读取商品名称        stmt = conn.prepareStatement("select * from Ware where wareID=" + wareID);        rs = stmt.executeQuery();        if (rs.next())          wareName = rs.getString("wareName");        rs.close();        stmt.close();        //读取商品库存数量        stmt = conn.prepareStatement("select * from Reserve where wareID=" + wareID);        rs = stmt.executeQuery();        if (rs.next())          resQty = rs.getString("resQty");        rs.close();      }      catch(java.sql.SQLException e){        System.err.print(e);      }      finally {        //关闭数据库资源        if (stmt != null) {          try {            stmt.close();          } catch (Exception exception) {}        }        if (conn != null) {          try {            conn.close();          } catch (Exception exception) {}        }      }      request.setAttribute("wareName", wareName);      request.setAttribute("salePrice", new Float(salePrice));      request.setAttribute("saleQty", new Integer(saleQty));      request.setAttribute("saleDate", saleDate);      request.setAttribute("resQty", resQty);      getServletContext().getRequestDispatcher("/buyInfo.jsp").forward(request, response);    }    else{      response.setContentType(CONTENT_TYPE);      PrintWriter out = response.getWriter();      out.println("<html>");      out.println("<head><title>SaleServlet</title></head>");      out.println("<body bgcolor=\"#ffffff\">");      out.println("<p>error!</p>");      out.println("</body></html>");    }  }  //Process the HTTP Post request  public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {    doGet(request, response);  }  //Clean up resources  public void destroy() {  }}

⌨️ 快捷键说明

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