谁能教我做个简单的购物袋,只要单击一个物品就跳到购物袋中去,先谢了
解决方案 »
- java读取文本文件数据排序(数据10万条)
- 希望尽可能详细的了解Java技术
- eclipse加载wtp后还是没有动态web 只有静态web
- 求救:MyEclipse7.5下启动server出错,直接运行server没错,
- 请问为什么有session的页面不能运行?其它页面正常.在线等。。谢谢
- 请教哪里有jsp中三级树形菜单的源代码?
- 我在servlet转发页面,页面里的资源路径都被进了一层,如何解决?
- 在jsp中怎样打印从数据库中读出显示在表格中的数据?
- 那一种JSP服务器支持HTTPS验证,其如何配置与实现!!!!!!!
- HttpClient get 方法传递json参数的问题
- 取前N条记录
- java文件上传问题
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import com.ebook.bean.*;
public class ViewCart extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1434458861240420653L;
/**
* Destruction of the servlet. <br>
*/
int count=1;
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession(false);
Bookbean book=(Bookbean)session.getAttribute("book");
Map map=new HashMap();
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
if(session.getAttribute("map")==null)
{
Cartbean cart=new Cartbean();
cart.setBook(book);
cart.setCount(1);
map.put(book.getIsbn(),cart);
session.setAttribute("map", map);
response.sendRedirect("/ebokk/html/viewcart.jsp");
//request.getRequestDispatcher("/html/viewcart.jsp").forward(request, response);
}
else
{
String str=null;
map=(HashMap)session.getAttribute("map");
Set set= map.keySet();
Iterator it=set.iterator();
while(it.hasNext())
{
str=(String)it.next();
if(book.getIsbn().equals(str))
{
break;
}
}
if(book.getIsbn().equals(str))
{
count++;
Cartbean cart=new Cartbean();
cart.setBook(book);
cart.setCount(count);
map.put(book.getIsbn(),cart);
session.setAttribute("map",map);
response.sendRedirect("/ebokk/html/viewcart.jsp");
}
else
{
Cartbean cart=new Cartbean();
cart.setBook(book);
cart.setCount(1);
map.put(book.getIsbn(),cart);
session.setAttribute("map", map);
response.sendRedirect("/ebokk/html/viewcart.jsp");
}
}
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}}bookbean:package com.ebook.bean;public class Bookbean {
private String isbn;
private String title;
private int editionNumber;
private String copyrigtht;
private int publisherid;
private String imgfile;
private double price;
public String getCopyrigtht() {
return copyrigtht;
}
public void setCopyrigtht(String copyrigtht) {
this.copyrigtht = copyrigtht;
}
public int getEditionNumber() {
return editionNumber;
}
public void setEditionNumber(int editionNumber) {
this.editionNumber = editionNumber;
}
public String getImgfile() {
return imgfile;
}
public void setImgfile(String imgfile) {
this.imgfile = imgfile;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getPublisherid() {
return publisherid;
}
public void setPublisherid(int publisherid) {
this.publisherid = publisherid;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}购物车bean:
package com.ebook.bean;
public class Cartbean {
private Bookbean book;
private int count;
public Bookbean getBook() {
return book;
}
public Cartbean(Bookbean book,int count)
{}
public Cartbean()
{}
public void setBook(Bookbean book) {
this.book = book;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
private String isbn; //书本编号
private String title; //书的名字
private int editionNumber; //作者ID
private String copyrigtht; //版权
private int publisherid; //出版ID
private String imgfile; //图片地址
private double price; //价格