2014Java与大数据
2016-9-4 10:01/** *作业:实现购物车功能 *姓名:程菊飞 *学号:2014011729 *班级:软件四班 **/ /*****IndexServlet.java*******/ package controller; import java.io.IOException; imp...
/** * * 任务:购物车例子 * 班级:六班 * 学号:2014011817 * 姓名:李盈 * * */ //****************IndexServlet.java*************** package controller;...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.Servlet; import...
我把作业交到ftp中了。是个压缩文件夹,麻烦老师下载一下。 网址为:http://10.7.1.98/201404tianruihang/Java%E4%B8%8E%E5%A4%A7%E6%95%B0%E6%8D%AE%E4%BD%9C%E4%B8%9A/ ...
这是商品购物车的功能实现,请查收: http://10.7.1.98/201404sunyongguo/javaee/
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExcepti...
/* 姓名:刘松 班级:五班 学号:2014011760 */ package controller; import java.io.IOException; import java.io.PrintWriter; import java.util.List; impo...
/***********com.AddCart***********/ package com; import java.io.IOException; import java.util.ArrayList; import java.util.List; import...
AddCartServlet.java: package com.cookie; import java.io.IOException; import java.util.ArrayList; import java.util.List; impo...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
package controller; /* *一班 *沈晨阳 */ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
package com.servlet; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExcepti...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
/* AddCartServlet */ package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import ja...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
已完成, 作业连接: http://10.7.1.98/201403majia/JavaWeb/2016-9/ShoppingCart/ShoppingCart.zip
//6班,穆翔宇,2014011793 import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletException...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExceptio...
----------------------------IndexServlet.java----------------------------------------------- package test; /** * 功能:展示商品首页,若没有登录,会提示登录,...
package controller; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletExcept...
/**********LoginServlet.java***************/ /** * 姓名:郭爽 * 班级:1班 * 学号:2014011573 */ package servlet; import java.io.IOException; ...
package controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class AddCartServlet
*/
@WebServlet("/AddCartServlet")
public class AddCartServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddCartServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//判断Cookie信息是否存在,存在直接添加到购物车,否则显示登录页面
String name=request.getParameter("name");
name=new String(name.getBytes("iso-8859-1"),"utf-8");
System.out.println("商品名:"+name);
HttpSession session=request.getSession();
List<String> cart=(List<String>) session.getAttribute("cart");
if(cart == null){
cart=new ArrayList<String>();
cart.add(name);
}else{
cart.add(name);
}
session.setAttribute("cart",cart);
response.sendRedirect("index.html");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class IndexServlet
*/
@WebServlet("/IndexServlet")
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public IndexServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Cookie[] cookies = request.getCookies();
if(cookies!=null){
String name=null;
String pwd=null;
System.out.println("cookie !=null");
for(Cookie cookie:cookies){
System.out.println("name:"+cookie.getName());
System.out.println("value:"+cookie.getValue());
if(cookie.getName().equals("name")){
name=cookie.getValue();
}
if(cookie.getName().equals("pwd")){
pwd = cookie.getValue();
}
}
if(name.equals("admin")&&pwd.equals("1234")){
System.out.println("doget --cookie");
request.getRequestDispatcher("index.html").forward(request,response);
return;
}
}
response.encodeRedirectURL("login.html");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String name = request.getParameter("userName");
String pwd = request.getParameter("userPwd");
//访问数据库,查看用户是否存在
if(name!=null && name.equals("admin") && pwd!=null && pwd.equals("1234")){
String autoLogin = request.getParameter("autoLogin");
if(autoLogin!=null&&autoLogin.equals("on")){
//响应的处理,保存用户名密码到cookie中
System.out.println("autoLogin:"+autoLogin);
Cookie c1 = new Cookie("name",name);
Cookie c2 = new Cookie("pwd",pwd);
c1.setMaxAge(5*60);
c2.setMaxAge(5*60);
response.addCookie(c1);
response.addCookie(c2);
}
request.getRequestDispatcher("index.html").forward(request, response);
return;
}
response.sendRedirect("login.html");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
package controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class ShowCartServlet
*/
@WebServlet("/ShowCartServlet")
public class ShowCartServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ShowCartServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
HttpSession session = request.getSession();
List<String> cart = (List<String>) session.getAttribute("cart");
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.write("<html><head><title>购物车</title></head><body><hr>");
for (int i = 0; i < cart.size(); i++)
{
if(i==cart.size()-1){
out.write("购物车中商品的数量为"+i);
break;
}
out.write("商品名:" + cart.get(i));
System.out.println("商品名:" + cart.get(i));
out.write("<hr>");
}
out.write("</body></html>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>
<table>
<tr>
<td>商品名</td> <td>商品A </td>
</tr>
<tr>
<td>商品描述</td> <td>男装</td>
</tr>
</table>
<a href="index.html">返回首页</a>
<a href="addCart?id=1&name=商品A">添加到购物车</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>
<table>
<tr>
<td>商品名</td>
<td>商品B</td>
</tr>
<tr>
<td>商品描述</td>
<td>女装</td>
</tr>
</table>
<a href="index.html">返回首页</a>
<a href="addCart?id=2&name=商品B">添加到购物车</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>详细信息</title>
</head>
<body>
<table>
<tr>
<td>商品名</td>
<td>商品C</td>
</tr>
<tr>
<td>商品描述</td>
<td>童装</td>
</tr>
</table>
<a href="index.html">返回首页</a>
<a href="addCart?id=3&name=商品C">添加到购物车</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品列表</title>
</head>
<body>
<table>
<tr>
<td>商品名</td>
<td>价格</td>
<td colspan="2">操作</td>
</tr>
<tr>
<td>商品A</td>
<td>35</td>
<td><a href="detailA.html">查看详情</a></td>
<td><a href=addCart?id=1&name=商品A>添加到购物车</a></td>
</tr>
<tr>
<td>商品B</td>
<td>40</td>
<td><a href="detailB.html">查看详情</a></td>
<td><a href="addCart?id=2&name=商品B">添加到购物车</a></td>
</tr>
<tr>
<td>商品C</td>
<td>45</td>
<td><a href="detailC.html">查看详情</a></td>
<td><a href="addCart?id=3&name=商品C">添加到购物车</a></td>
</tr>
</table>
<a href="showCart">查看购物车</a>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="login" method="post">
<table border="1">
<tr>
<td width="100">用户名:</td>
<td><input type="text" name="userName"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="userPwd"></td>
</tr>
<tr>
<td><input type="reset" value="重置" /></td>
<td><input type="submit" value="登录" /> <input type="radio"
value="on" name="autoLogin" /> 自动登录</td>
</tr>
</table>
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>shoppingcar</display-name>
<welcome-file-list>
<welcome-file>index.do</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>IndexServlet</servlet-name>
<servlet-class>controller.IndexServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>IndexServlet</servlet-name>
<url-pattern>/index.do</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AddCartServlet</servlet-name>
<servlet-class>controller.AddCartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AddCartServlet</servlet-name>
<url-pattern>/addCart</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ShowCartServlet</servlet-name>
<servlet-class>controller.ShowCartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShowCartServlet</servlet-name>
<url-pattern>/showCart</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>controller.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>
/*名称:购物车-首页 *姓名:张潇洁 *学号:2014011666 *班级:3班 */ package controller; import java.io.IOException; import javax.servlet.ServletException; imp...
package controller; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; impo...
/* 班级:1班 姓名:赵冬雪 学号:2014011572 功能:使用HttpSession实现购物车功能 */ 1./* web.xml <?xml version="1.0" encoding="UTF-8"?> <web...
/* 姓名:王子津 班级:2014级一班 学号:2014011540 */ web.xml 文件夹 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.o...
package controller; /** * 姓名:童海苹 * 学号:2014011625 * 功能:添加购物车 */ import java.io.IOException; import java.util.ArrayList; import java.ut...