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

📄 product_0002ejsp_jsp.java

📁 购物车模块实例。购物车模块可以浏览商品类别;可以根据商品类别浏览商品信息;可以购买商品;可以查看购物车的商品;可以修改购买商品的数量和删除购买的商品。
💻 JAVA
字号:
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class product_0002ejsp_jsp extends HttpJspBase {

    // begin [file="/product.jsp";from=(5,0);to=(5,67)]
    // end

    static {
    }
    public product_0002ejsp_jsp( ) {
    }

    private static boolean _jspx_inited = false;

    public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
    }

    public void _jspService(HttpServletRequest request, HttpServletResponse  response)
        throws java.io.IOException, ServletException {

        JspFactory _jspxFactory = null;
        PageContext pageContext = null;
        HttpSession session = null;
        ServletContext application = null;
        ServletConfig config = null;
        JspWriter out = null;
        Object page = this;
        String  _value = null;
        try {

            if (_jspx_inited == false) {
                synchronized (this) {
                    if (_jspx_inited == false) {
                        _jspx_init();
                        _jspx_inited = true;
                    }
                }
            }
            _jspxFactory = JspFactory.getDefaultFactory();
            response.setContentType("text/html; charset=GBK");
            pageContext = _jspxFactory.getPageContext(this, request, response,
            			"", true, 8192, true);

            application = pageContext.getServletContext();
            config = pageContext.getServletConfig();
            session = pageContext.getSession();
            out = pageContext.getOut();

            // HTML // begin [file="/product.jsp";from=(0,48);to=(5,0)]
                out.write("\r\n<html>\r\n<head>\r\n<title>商品浏览页面</title>\r\n</head>\r\n");

            // end
            // begin [file="/product.jsp";from=(5,0);to=(5,67)]
                data.CartData cartData = null;
                boolean _jspx_specialcartData  = false;
                 synchronized (session) {
                    cartData= (data.CartData)
                    pageContext.getAttribute("cartData",PageContext.SESSION_SCOPE);
                    if ( cartData == null ) {
                        _jspx_specialcartData = true;
                        try {
                            cartData = (data.CartData) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "data.CartData");
                        } catch (ClassNotFoundException exc) {
                             throw new InstantiationException(exc.getMessage());
                        } catch (Exception exc) {
                             throw new ServletException (" Cannot create bean of class "+"data.CartData", exc);
                        }
                        pageContext.setAttribute("cartData", cartData, PageContext.SESSION_SCOPE);
                    }
                 } 
                if(_jspx_specialcartData == true) {
            // end
            // begin [file="/product.jsp";from=(5,0);to=(5,67)]
                }
            // end
            // HTML // begin [file="/product.jsp";from=(5,67);to=(8,0)]
                out.write("\r\n<body>\r\n<center>\r\n");

            // end
            // begin [file="/product.jsp";from=(8,2);to=(15,0)]
                
                //设置取得参数的编码方式
                request.setCharacterEncoding("GBK");
                //取得类别ID
                int categoryId = Integer.parseInt(request.getParameter("categoryId"));
                //取得类别名称
                String categoryName = request.getParameter("categoryName");
            // end
            // HTML // begin [file="/product.jsp";from=(15,2);to=(16,4)]
                out.write("\r\n<h3>");

            // end
            // begin [file="/product.jsp";from=(16,7);to=(16,19)]
                out.print(categoryName);
            // end
            // HTML // begin [file="/product.jsp";from=(16,21);to=(18,46)]
                out.write("类别的商品显示页面</h3>\r\n<form action=\"goodsview\" method=\"post\">\r\n<input name=\"categoryId\" type=\"hidden\" value=\"");

            // end
            // begin [file="/product.jsp";from=(18,49);to=(18,59)]
                out.print(categoryId);
            // end
            // HTML // begin [file="/product.jsp";from=(18,61);to=(19,48)]
                out.write("\">\r\n<input name=\"categoryName\" type=\"hidden\" value=\"");

            // end
            // begin [file="/product.jsp";from=(19,51);to=(19,63)]
                out.print(categoryName);
            // end
            // HTML // begin [file="/product.jsp";from=(19,65);to=(33,0)]
                out.write("\">\r\n<table cellpadding=\"5\" cellspacing=\"0\" border = \"1\">\r\n  <tr align=\"center\">\r\n    <td colspan=\"3\"><input name=\"action\" type=\"submit\" value=\"加入购物车\"></td>\r\n    <td colspan=\"3\"><input name=\"action\" type=\"submit\" value=\"查看购物车\"></td>\r\n  </tr>\r\n  <tr align=\"center\">\r\n    <td>序号</td>\r\n    <td>商品名字</td>\r\n    <td>单位数量</td>\r\n    <td>单价</td>\r\n    <td>是否购买</td>\r\n    <td>数量</td>\r\n  </tr>\r\n");

            // end
            // begin [file="/product.jsp";from=(33,2);to=(36,0)]
                
                //取得商品数组
                String[][] products = cartData.getProduct(categoryId);
            // end
            // HTML // begin [file="/product.jsp";from=(36,2);to=(37,45)]
                out.write("\r\n<input name=\"idsLength\" type=\"hidden\" value=\"");

            // end
            // begin [file="/product.jsp";from=(37,48);to=(37,63)]
                out.print(products.length);
            // end
            // HTML // begin [file="/product.jsp";from=(37,65);to=(38,0)]
                out.write("\">\r\n");

            // end
            // begin [file="/product.jsp";from=(38,2);to=(41,0)]
                
                for(int i=0; i < products.length; i++){
                  if(products[0].length > 1){
            // end
            // HTML // begin [file="/product.jsp";from=(41,2);to=(44,10)]
                out.write("\r\n    <!--通过表格显示商品数组的数据-->\r\n    <tr>\r\n      <td>");

            // end
            // begin [file="/product.jsp";from=(44,13);to=(44,20)]
                out.print((i + 1));
            // end
            // HTML // begin [file="/product.jsp";from=(44,22);to=(45,6)]
                out.write("</td>\r\n      ");

            // end
            // begin [file="/product.jsp";from=(45,8);to=(45,50)]
                for(int j=1; j < products[0].length; j++){
            // end
            // HTML // begin [file="/product.jsp";from=(45,52);to=(46,8)]
                out.write("\r\n        ");

            // end
            // HTML // begin [file="/product.jsp";from=(46,25);to=(47,12)]
                out.write("\r\n        <td>");

            // end
            // begin [file="/product.jsp";from=(47,15);to=(47,29)]
                out.print(products[i][j]);
            // end
            // HTML // begin [file="/product.jsp";from=(47,31);to=(48,6)]
                out.write("</td>\r\n      ");

            // end
            // begin [file="/product.jsp";from=(48,8);to=(48,9)]
                }
            // end
            // HTML // begin [file="/product.jsp";from=(48,11);to=(49,45)]
                out.write("\r\n      <td align=\"center\"><input name=\"goodsId");

            // end
            // begin [file="/product.jsp";from=(49,48);to=(49,49)]
                out.print(i);
            // end
            // HTML // begin [file="/product.jsp";from=(49,51);to=(50,13)]
                out.write("\" type=\"checkbox\" value=\"\r\n             ");

            // end
            // begin [file="/product.jsp";from=(50,16);to=(51,36)]
                out.print(products[i][0] + "@@" + products[i][1] + "@@" + products[i][2]
             + "@@" + products[i][3]);
            // end
            // HTML // begin [file="/product.jsp";from=(51,38);to=(52,31)]
                out.write("\"></td>\r\n      <td><input name=\"quantity");

            // end
            // begin [file="/product.jsp";from=(52,34);to=(52,35)]
                out.print(i);
            // end
            // HTML // begin [file="/product.jsp";from=(52,37);to=(54,0)]
                out.write("\" type=\"text\" size=\"15\"></td>\r\n    </tr>\r\n");

            // end
            // begin [file="/product.jsp";from=(54,2);to=(55,8)]
                
                  }else{
            // end
            // HTML // begin [file="/product.jsp";from=(55,10);to=(56,24)]
                out.write("\r\n    <tr><td colspan=\"6\">");

            // end
            // begin [file="/product.jsp";from=(56,27);to=(56,41)]
                out.print(products[i][0]);
            // end
            // HTML // begin [file="/product.jsp";from=(56,43);to=(57,0)]
                out.write("</td></tr>\r\n");

            // end
            // begin [file="/product.jsp";from=(57,2);to=(60,0)]
                
                  }
                }
            // end
            // HTML // begin [file="/product.jsp";from=(60,2);to=(66,7)]
                out.write("\r\n</table>\r\n</form>\r\n<h3><a href=\"category.jsp\">返回商品类别页面</a></h3>\r\n</center>\r\n</body>\r\n</html>");

            // end

        } catch (Throwable t) {
            if (out != null && out.getBufferSize() != 0)
                out.clearBuffer();
            if (pageContext != null) pageContext.handlePageException(t);
        } finally {
            if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
        }
    }
}

⌨️ 快捷键说明

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