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

📄 cart_0002ejsp_jsp.java

📁 用JAVA编写的网上书店程序
💻 JAVA
字号:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;


public class cart_0002ejsp_jsp extends HttpJspBase {

    // begin [file="/cart.jsp";from=(11,0);to=(11,52)]
    // end

    static {
    }
    public cart_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=GB18030");
            pageContext = _jspxFactory.getPageContext(this, request, response,
            			"", true, 8192, true);

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

            // HTML // begin [file="/cart.jsp";from=(0,52);to=(1,0)]
                out.write("\r\n");

            // end
            // HTML // begin [file="/cart.jsp";from=(1,47);to=(2,0)]
                out.write("\r\n");

            // end
            // begin [file="/cart.jsp";from=(2,2);to=(10,0)]
                
                /*检查客户是否通过登录,如果未经过登录检查,返回登录界面。
                *验证用户是否存在,避免用户直接进入该页,以后的每张动态网
                *页都要包括这一部分。*/
                if(session.getAttribute("username")==null)
                {
                  response.sendRedirect("login.html");
                }
            // end
            // HTML // begin [file="/cart.jsp";from=(10,2);to=(11,0)]
                out.write("\r\n");

            // end
            // begin [file="/cart.jsp";from=(11,0);to=(11,52)]
                book.bk bkId = null;
                boolean _jspx_specialbkId  = false;
                 synchronized (pageContext) {
                    bkId= (book.bk)
                    pageContext.getAttribute("bkId",PageContext.PAGE_SCOPE);
                    if ( bkId == null ) {
                        _jspx_specialbkId = true;
                        try {
                            bkId = (book.bk) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "book.bk");
                        } catch (ClassNotFoundException exc) {
                             throw new InstantiationException(exc.getMessage());
                        } catch (Exception exc) {
                             throw new ServletException (" Cannot create bean of class "+"book.bk", exc);
                        }
                        pageContext.setAttribute("bkId", bkId, PageContext.PAGE_SCOPE);
                    }
                 } 
                if(_jspx_specialbkId == true) {
            // end
            // begin [file="/cart.jsp";from=(11,0);to=(11,52)]
                }
            // end
            // HTML // begin [file="/cart.jsp";from=(11,52);to=(12,0)]
                out.write("\r\n");

            // end
            // begin [file="/cart.jsp";from=(12,2);to=(50,0)]
                
                String book_id=request.getParameter("book_id");
                //是否已经选择该书
                String sql="select id from 订单表 where book_id="+book_id+" and user_name='"+session.getAttribute("username")+"'";
                ResultSet rs=bkId.executeQuery(sql);
                int rowscount=0;
                try
                {
                  while(rs.next())
                  {
                    rowscount++;
                  }
                }
                catch(Exception e)
                {
                }
                //把图书放入购物车
                if(rowscount==0)
                {
                  String sqlBook1="select * from 书籍信息表 where id="+book_id;
                  ResultSet rsBook1=bkId.executeQuery(sqlBook1);
                  while(rsBook1.next())
                  {
                    String sqlCart="insert into 订单表 (user_name,book_id,book_number,goods_price) Values('"+session.getAttribute("username")+"','"+book_id+"','1','"+rsBook1.getDouble("price")+"')";
                    bkId.executeQuery(sqlCart);
                  }
                }
                else
                {
                  String sqlBook2="select * from 书籍信息表 where id="+book_id;
                  ResultSet rsBook2=bkId.executeQuery(sqlBook2);
                  while(rsBook2.next())
                  {
                    String sqlAdd="update 订单表 set book_number=book_number+1,goods_price="+rs.getDouble("price")+" where book_id="+book_id+" and user_name='"+session.getAttribute("uesername")+"'";
                    bkId.executeQuery(sqlAdd);
                  }
                }
                response.sendRedirect("shopcart.jsp");
            // end
            // HTML // begin [file="/cart.jsp";from=(50,2);to=(51,0)]
                out.write("\r\n");

            // 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 + -