我用SSH做项目,用分发ACTION跳转页面,成功给查询MYSQL中的数据,却不知道怎样把查到的数据加入购物车,求各位老师给予指点
解决方案 »
- 求高手指教 maven项目ibatis 错误
- java基础,却难倒了好多大牛
- 如何给tomcat的启动中加入一个dll文件的路径
- 急求!!oracle9i dblink ora-12154:tns无法处理服务器名 问题
- jsp / Servelt 问题,在线等~!
- (SSH项目)关于用户登陆问题.
- WebLogic与J2EE
- 新年了,分不多,也散点吧1◎◎
- 请问各位,产生java程序编译中找不着classpath的错误,有哪几种现象?都有哪些解决方法?
- 使用springCloud熔断器添加依赖后加入@EnableHystrix注解报错
- myEclipse8.5启动tomcat6.0时出错
- 收藏本站 网页功能怎么做的?
shopping_car.jsp<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="java.util.*"%>
<%
request.setCharacterEncoding("GBK");
%>
<%
int pid=0;
int pnum=0;
try
{
pid=Integer.parseInt(request.getParameter("pid"));
}
catch(Exception ex)
{
}
Map<Integer,Integer> mp=(Map<Integer,Integer>)session.getAttribute("shoppingCar");
if(mp==null)
{
mp=new HashMap<Integer,Integer>();
}
if(mp.get(pid)==null)
{
mp.put(pid,1);
}
else
{
pnum=mp.get(pid);
pnum++;
mp.put(pid,pnum);
}
session.setAttribute("shoppingCar",mp);
%>
<jsp:forward page="shopping_car_list.jsp"/>
shopping_car_list.jsp<%@ page contentType="text/html" pageEncoding="GBK"%>
<%@ page import="org.xiong.demo.vo.*,org.xiong.demo.factory.*,java.util.*"%>
<%-- <%@ page import="java.sql.*,java.util.*"%> --%>
<%
request.setCharacterEncoding("GBK");
%>
<script language="javascript">
function ProductCheck()
{
window.location="product_check.jsp";
}
</script>
<%
Map mp=(Map)session.getAttribute("shoppingCar");
List<Product> allProduct=null;
if(mp!=null)
{
Set kst=mp.keySet();
allProduct=DaoFactory.getProductDaoInstance().findShoppingCar(kst);%>
<center>
<h1>已添加至购物车中的商品</h1>
</center>
<form action="update_product.jsp" method="post">
<table border="1" width="100%">
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>简介</th>
<th>价格</th>
<th>购买数量</th>
<th>累计点击率</th>
</tr>
<%
Iterator<Product> iterPro=allProduct.iterator();
while(iterPro.hasNext())
{
Product pr=iterPro.next();
int pid=pr.getPid();
String name=pr.getName();
String note=pr.getNote();
float price=pr.getPrice();
int amount=pr.getAmount();
int cnt=pr.getCount();
%>
<tr>
<th><%=pid%></th>
<th><%=name%></th>
<th><%=note%></th>
<th><%=price%></th>
<th><input name="<%=pid%>" value="<%=mp.get(pid)%>" size="3" maxlength="3"/></th>
<th><%=cnt%></th>
</tr>
<%
}
%>
<tr >
<th colspan="6"><input type="submit" value="保存修改" /> <input type="button" value="生成订单" onClick="ProductCheck()"/></th>
</tr>
</table>
</form>
<%
}
else
{
%>
<table border="1" width="100%">
<tr>
<th>购物车中没有添加商品!</th>
</tr>
</table>
<%
}
%>
<%@ page import="java.sql.*,java.util.*,org.gjt.mm.mysql.*"%>
<html>
<%
request.setCharacterEncoding("UTF-8");
%>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingchart?useUnicode=true&characterEncoding=UTF-8", "root","123");
Statement stmt=conn.createStatement();
ResultSet rest=stmt.executeQuery("select * from shoppingchart where userId=12");
%>
<h1>已添加至购物车中的商品</h1>
<form action="update_product.jsp" method="post">
<table border="1" width="100%">
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>简介</th>
<th>价格</th>
<th>购买数量</th>
</tr>
<%
while(rest.next())
{
int productId=rest.getInt(1);
String name=rest.getString(3);
String note=rest.getString(4);
String price=rest.getString(5);
int amount=rest.getInt(6);
%>
<tr>
<th><%=productId%></th>
<th><%=name%></th>
<th><%=note%></th>
<th><%=price%></th>
<th><%=amount%></th>
</tr>
<%
}
%>
</table>
</form>
<%
}catch(Exception e){
%>
<%=e %>
<%
}
%>
</html>
<%@ page import="java.sql.*,java.util.*,org.gjt.mm.mysql.*"%>
<html>
<%
request.setCharacterEncoding("UTF-8");
%>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingchart?useUnicode=true&characterEncoding=UTF-8", "root","123");
Statement stmt=conn.createStatement();
ResultSet rest=stmt.executeQuery("select * from shoppingchart where userId=12");
%>
<h1>已添加至购物车中的商品</h1>
<form action="update_product.jsp" method="post">
<table border="1" width="100%">
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>简介</th>
<th>价格</th>
<th>购买数量</th>
</tr>
<%
while(rest.next())
{
int productId=rest.getInt(1);
String name=rest.getString(3);
String note=rest.getString(4);
String price=rest.getString(5);
int amount=rest.getInt(6);
%>
<tr>
<th><%=productId%></th>
<th><%=name%></th>
<th><%=note%></th>
<th><%=price%></th>
<th><%=amount%></th>
</tr>
<%
}
%>
</table>
</form>
<%
}catch(Exception e){
%>
<%=e %>
<%
}
%>
</html>
<%@ page import="java.sql.*,java.util.*"%>
<html>
<%
request.setCharacterEncoding("UTF-8");
%>
<%
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingchart?useUnicode=true&characterEncoding=UTF-8", "root","123");
Statement stmt=conn.createStatement();
ResultSet rest=stmt.executeQuery("select * from shoppingchart where userId=12");
%>
<h1>已添加至购物车中的商品</h1>
<form action="update_product.jsp" method="post">
<table border="1" width="100%">
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>简介</th>
<th>价格</th>
<th>购买数量</th>
</tr>
<%
while(rest.next())
{
int productId=rest.getInt(1);
String name=rest.getString(3);
String note=rest.getString(4);
String price=rest.getString(5);
int amount=rest.getInt(6);
%>
<tr>
<th><%=productId%></th>
<th><%=name%></th>
<th><%=note%></th>
<th><%=price%></th>
<th><%=amount%></th>
</tr>
<%
}
%>
</table>
</form>
<%
}catch(Exception e){
%>
<%=e %>
<%
}
%>
</html>
刚发的排版有点乱我这个是从数据库中查出来的,但是感觉还是应该存在客户端cookie中比较好