姚明Jsp第三次实验报告
Java web应用编程基础实验报告
实验3:内置对象、Cookie实验
姓名:___ 林浩强 ___班级:___网络14-2班 _ _ 学号:_ 14034460220____成绩:_____
一、实验目的:
●理解对象概念,掌握application、session等对象的基本使用方法。
●理解Cookie概念,掌握Cookie的基本使用方法。
二、实验要求:
●使用专业开发工具MyEclipse编程。
●上交实验报告电子文档(文档包含源程序,以班级、学号、姓名依次出现组成的
字符串标识文档,以班级为单位上交)。
●
三、实验内容:
1、编写一个简单的网上商店,用application对象存放网上的商品清单和库存量,用session 对象存放用户的购买信息(用户名、商品名及购买数量),然后利用这些信息给用户结账。
(1)通过applicationShop添加商品信息,并添加购买系统的登录超级链接
(2)通过onlineShopLogin.jsp实现登录界面,并输入用户名和密码,经由checkLogin.jsp检验
(3)通过sessionShop.jsp实现购买界面,购买商品并提交
(4)通过sessionData.jsp处理数据并传至customer.jsp显示出用户结算界面
(5)通过点击超链接可以继续购买商品
(6)购买商品自动跳入用户结算界面
2、利用Cookie实现用户的自动登录功能。其中,要求在登录页面中通过对Cookie有效期的设置来保存用户的信息。
(1) 通过applicationShop添加商品信息,并添加购买系统的登录超级链接
(2)通过cookie保留的用户名和密码进行自动登录,进入购买界面
(3)购买商品
(4)进入用户结算界面
四、实验过程中遇到的问题及解决手段:
在实验过程中,对jsp标签的使用不是很熟悉,查阅资料后就清楚了哪些情况要插入标签,哪些情况可以插入jsp代码,以及跟html语句的结合使用,都有了一定的了解。
五、程序源代码:
applicationShop.jsp
<%@page language="java"import="java.util.*"
contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%>
<%
String pencil="铅笔";
String pen="钢笔";
String eraser="橡皮";
String sharpener="卷笔刀";
double pencilPrice=1.00;
double penPrice=2.00;
double eraserPrice=0.5;
double sharpenerPrice=3.00;
int pencilStorage=20;
int penStorage=25;
int eraserStorage=30;
int sharpenerStorage=30;
if(application.getAttribute("pencilAmount")!=null){
int
a=Integer.parseInt(application.getAttribute("pencilStorage").toString ());
int
pencilSell=Integer.parseInt(application.getAttribute("pencilAmount"). toString());
pencilStorage=a-pencilSell;
}
if(application.getAttribute("penAmount")!=null){
int
penSell=Integer.parseInt(application.getAttribute("penAmount").toStri ng());
penStorage=25-penSell;
}
if(application.getAttribute("eraserAmount")!=null){
int
eraserSell=Integer.parseInt(application.getAttribute("eraserAmount"). toString());
eraserStorage=30-eraserSell;
}
if(application.getAttribute("sharpenerAmount")!=null){
int
sharpenerSell=Integer.parseInt(application.getAttribute("sharpenerAmo unt").toString());
sharpenerStorage=30-sharpenerSell;
}
%>
商品名 | 价格 | 库存 |
---|---|---|
<%=pencil%> | <%=pencilPrice%> | <%=pencilStorage%> td> |
<%=pen%> | <%=penPrice%> | <%=penStorage%> |
<%=eraser%> | <%=eraserPrice%> | <%=eraserStorage%> td> |
<%=sharpener%> | <%=sharpenerPrice%> | <%=sharpenerSt orage%> |
<%
application.setAttribute("pencil",pencil);
application.setAttribute("pen",pen);
application.setAttribute("eraser",eraser);
application.setAttribute("sharpener",sharpener);
application.setAttribute("pencilPrice",pencilPrice);
application.setAttribute("penPrice",penPrice);
application.setAttribute("eraserPrice",eraserPrice);
application.setAttribute("sharpenerPrice",sharpenerPrice); application.setAttribute("pencilStorage",pencilStorage);
application.setAttribute("penStorage",penStorage);
application.setAttribute("eraserStorage",eraserStorage);
application.setAttribute("sharpenerStorage",sharpenerStorage);
%>
onlineShopLogin.jsp
<%@page contentType="text/html;charset=gb2312"%>
<%
Cookie cookies[] = request.getCookies();
int count = cookies.length;
String name = "",password = "";
for(int i = 0;i < count;i++)
if(cookies[i].getName().equals("name"))
name = cookies[i].getValue();
if(name == ""){
%>
运行结果:jsp实验报告49775
Jsp实验报告 课程设计名称:兼职网站 系:交通运输管理学院学生姓名: 班级: 学号: 成绩: 指导教师: 开课时间:2013学年第2 学期
一.设计题目 兼职网站 二.主要内容 本网站涉及兼职信息、用户信息的数据管理。从管理的角度可将信息分为两类:兼职信息管理、用户数据管理。用户数据管理为用户的登录判定,兼职信息管理包括兼职信息显示及兼职信息的录入、查询和删除。 (1)用户的登录判定 (2)录入兼职的信息,并保存到数据库中 (3)根据用户的需求选择查询方式,查询相关兼职信息 (4)将信息从数据库中删除 三.具体要求 (1)建立数据库表格存储用户数据(用户名及密码)。 (2)建立数据库表格存储兼职信息,主要包括ID、兼职名称、地点、工资和联系方式。 (3)编写jsp 语句连接数据库 (4)利用request函数提交表单,获取输入信息 (5)以SQL语句对数据库进行操作,完成信息的添加,查询及删除等功能。四.进度安排 五.成绩评定 正文 1、系统的需求分析和功能设计 随着电子信息在人们生活中的的使用比重不断增加,人们越来越习惯在网站上查找自己所需
要的信息不仅仅只是因其快捷,更因其接触的面更加广泛,信息的基础量足够大,足以满足人们更加细化的需求。在寻找兼职体验工作生活或赚取生活费用时,可以减少时间的浪费及其他不必要的消耗。 本网站涉及兼职信息、用户信息的数据管理。从管理的角度可将信息分为两类:兼职信息管理、用户数据管理。用户数据管理为用户的登录判定,兼职信息管理包括兼职信息显示及兼职信息的录入、查询和删除。用户登录后可以根据自己的需要对信息进行添加、查询和删除的操作 2、源程序及注释 主页:<%@page language="java"contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>