文件名称:网上购物系统设计与实现
文件大小:1.29MB
文件格式:DOC
更新时间:2015-12-28 10:55:17
网上购物
网上购物系统设计和实现课程设计
四、程序关键代码及效果图
1、过滤器代码:[只要doFilter()方法]
(1)adminfilter.java:
HttpServletRequest requ=(HttpServletRequest)req;
res.setCharacterEncoding("gb18030");
requ.setCharacterEncoding("gb18030");
HttpSession session=requ.getSession();
if(session.getAttribute("admin")==null){
PrintWriter out=res.getWriter();
out.println("[removed]");
out.println("alert('您还没有登录!');");
out.println("[removed].href='../login_admin.jsp';");
out.println("[removed]");
}else{
chain.doFilter(req, res);
}
(2)userfilter.java:
HttpServletRequest requ=(HttpServletRequest)req;
res.setCharacterEncoding("gb18030");
requ.setCharacterEncoding("gb18030");
HttpSession session=requ.getSession();
if(session.getAttribute("uname")==null){
PrintWriter out=res.getWriter();
out.println("[removed]");
out.println("alert('您还没有登录!');");
out.println("[removed].href='../login.html';");
out.println("[removed]");
}else{
chain.doFilter(req, res);
}
(3)Encodingfilter.java:
HttpServletRequest request=(HttpServletRequest)req;
request.setCharacterEncoding("gb18030");
HttpServletResponse response=(HttpServletResponse)res;
response.setCharacterEncoding("gb18030");
chain.doFilter(req, res);
}
2、Servlet代码:[只要doPost()或doGet()方法]
(1)add.java:
response.setContentType("text/html");
request.setCharacterEncoding("gb18030");
HttpSession session=request.getSession();
CartBean cb=new CartBean();
Vector