📄 cart_jsp.java
字号:
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import bean.*;
import java.util.*;
public final class cart_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static java.util.List _jspx_dependants;
public Object getDependants() {
return _jspx_dependants;
}
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;
JspWriter _jspx_out = null;
PageContext _jspx_page_context = null;
try {
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=gb2312");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("\r\n");
bean.Products products = null;
synchronized (session) {
products = (bean.Products) _jspx_page_context.getAttribute("products", PageContext.SESSION_SCOPE);
if (products == null){
products = new bean.Products();
_jspx_page_context.setAttribute("products", products, PageContext.SESSION_SCOPE);
}
}
out.write('\r');
out.write('\n');
bean.Cart cart = null;
synchronized (session) {
cart = (bean.Cart) _jspx_page_context.getAttribute("cart", PageContext.SESSION_SCOPE);
if (cart == null){
cart = new bean.Cart();
_jspx_page_context.setAttribute("cart", cart, PageContext.SESSION_SCOPE);
out.write('\r');
out.write('\n');
}
}
out.write("\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<title>car</title>\r\n");
out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">\r\n");
out.write("</head>\r\n");
out.write("\r\n");
//action为执行的操作,add表示添加此商品,remove表示删除此商品。
String action=request.getParameter("action");
//获得所有添加、删除的商品的itemid。
String items[]=request.getParameterValues("itemId");
if(items!=null)
for(int i=0;i<items.length;i++)
{
if(action.equals("add")) cart.addItem(items[i],1);
else if(action.equals("remove"))cart.removeItem(items[i]);
}
out.write("\r\n");
out.write("\r\n");
out.write("<body>\r\n");
out.write("\r\n");
out.write("<center>\r\n");
out.write("<form action=\"cart.jsp\" method=get>\r\n");
out.write("<table width=\"75%\" border=\"1\" bordercolor=\"#006633\">\r\n");
out.write(" <tr bgcolor=\"#999999\">\r\n");
out.write(" <td>id</td>\r\n");
out.write(" <td>名称</td>\r\n");
out.write(" <td>数量</td> \r\n");
out.write(" </tr>\r\n");
out.write(" ");
java.util.HashMap cart_item=cart.getItems();
Iterator it=cart_item.keySet().iterator();
while(it.hasNext())
{
String itemId=(String)it.next();
Item item=products.getItem(itemId);
out.write("\r\n");
out.write(" <tr>\r\n");
out.write(" <td><input type=\"checkbox\" name=\"itemId\" value=\"");
out.print(item.getItemId());
out.write("\"></td> \r\n");
out.write(" <td>");
out.print(item.getDescription());
out.write("</td>\r\n");
out.write("\t <td>");
out.print(cart_item.get(itemId));
out.write("</td> \r\n");
out.write(" </tr>\r\n");
out.write(" ");
}
out.write("\r\n");
out.write(" <tr align=left><td colspan=5><input type=submit value=\"remove\" name=\"action\"></td></tr> \r\n");
out.write(" <tr align=left><td colspan=5><a href=\"shopping.jsp\">购物</a>『』<a href=\"logout.jsp\">注销</a></td></tr>\r\n");
out.write("</table>\r\n");
out.write("</form></center>\r\n");
out.write("</body></html>\r\n");
} catch (Throwable t) {
if (!(t instanceof SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -