北邮信网jsp动态网页实验报告Word下载.docx

上传人:b****8 文档编号:22715940 上传时间:2023-02-05 格式:DOCX 页数:14 大小:556.95KB
下载 相关 举报
北邮信网jsp动态网页实验报告Word下载.docx_第1页
第1页 / 共14页
北邮信网jsp动态网页实验报告Word下载.docx_第2页
第2页 / 共14页
北邮信网jsp动态网页实验报告Word下载.docx_第3页
第3页 / 共14页
北邮信网jsp动态网页实验报告Word下载.docx_第4页
第4页 / 共14页
北邮信网jsp动态网页实验报告Word下载.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

北邮信网jsp动态网页实验报告Word下载.docx

《北邮信网jsp动态网页实验报告Word下载.docx》由会员分享,可在线阅读,更多相关《北邮信网jsp动态网页实验报告Word下载.docx(14页珍藏版)》请在冰豆网上搜索。

北邮信网jsp动态网页实验报告Word下载.docx

当前时间:

程序代码:

ShowProducts.jsp:

<

%@pagelanguage="

java"

import="

java.util.*"

pageEncoding="

GB18030"

%>

%@pageimport="

shoppingcar.*"

%

Stringpath=request.getContextPath();

StringbasePath=request.getScheme()+"

:

//"

+request.getServerName()+"

"

+request.getServerPort()

+path+"

/"

;

%>

!

DOCTYPEHTMLPUBLIC"

-//W3C//DTDHTML4.01Transitional//EN"

>

html>

head>

title>

MyJSP'

ShowProductsJSP.jsp'

startingpage<

/title>

metahttp-equiv="

pragma"

content="

no-cache"

cache-control"

expires"

0"

keywords"

keyword1,keyword2,keyword3"

description"

Thisismypage"

/head>

bodybgcolor="

#ffffff"

Mapproducts=newHashMap();

products.put("

1"

newProduct("

"

高考数学万能解题法"

"

王一"

18.00));

2"

五年高考三年模拟(高考物理)"

王二"

40.00));

3"

高考满分作文"

王三"

16.00));

4"

五年高考三年模拟(高考英语)"

王四"

48.00));

5"

学霸笔记"

王五"

23.00));

6"

五年高考三年模拟"

王六"

268.00));

7"

高考作文取胜之道"

王七"

20.00));

8"

高考作文必备素材"

武良良"

17.00));

9"

高考必刷题"

大卫"

11.00));

session.setAttribute("

products"

products);

<

h1align="

center"

这里是高考书院!

/h1>

scriptlanguage="

javascript"

alert('

这里是高考书店'

/script>

formname="

productForm"

action="

http:

//localhost:

8088/JSPlearning/ShopCartJSP.jsp"

method="

POST"

inputtype="

hidden"

name="

action"

value="

purchase"

tableborder="

cellspacing="

trbgcolor="

#CCCCCC"

td>

序号

/td>

产品名称

作者

产品单价(¥)

图片

添加到购物车

/tr>

SetproductIdSet=products.keySet();

Iteratorit=productIdSet.iterator();

intnumber=1;

intn=1;

while(it.hasNext()){

Stringid=(String)it.next();

Productproduct=(Product)products.get(id);

tr>

%=number++%>

%=product.getName()%>

%=product.getDescription()%>

%=product.getPrice()%>

imgsrc="

%=n++%>

.jpg"

align=left>

br>

/image>

ahref="

Buy.jsp?

id=<

%=product.getId()%>

&

action=add"

target="

cart"

购买<

/a>

}

/table>

p>

/p>

/form>

/body>

/html>

Buy.jsp

Cartc=(Cart)session.getAttribute("

);

if(c==null){

c=newCart();

c);

doubletotalPrice=c.getTotalPrice();

request.setCharacterEncoding("

GBK"

Stringaction=request.getParameter("

Mapproducts=(HashMap)session.getAttribute("

if(action!

=null&

action.trim().equals("

add"

)){

Stringid=request.getParameter("

id"

Productp=(Product)products.get(id);

CartItemci=newCartItem();

ci.setProduct(p);

ci.setCount

(1);

c.add(ci);

delete"

c.deleteItemById(id);

update"

for(inti=0;

i<

c.getItems().size();

i++){

CartItemci=c.getItems().get(i);

intcount=Integer.parseInt(request.getParameter("

p"

+ci.getProduct().getId()));

ci.setCount(count);

StringbasePath=request.getScheme()+"

+request.getServerName()+"

+request.getServerPort()+path+"

List<

CartItem>

items=c.getItems();

DOCTYPEhtmlPUBLIC"

//www.w3.org/TR/html4/loose.dtd"

Content-Type"

text/html;

charset=GB18030"

购物车<

styletype="

text/css"

body

{

background-image:

url(gaokao1.jpg);

background-repeat:

no-repeat;

background-attachment:

fixed;

background-position:

50%50%;

background-size:

100%;

}

/style>

body>

--c的值是:

%=(c==null)%>

items的值是:

%=(items==null)%>

-->

formaction="

Buy.jsp"

get"

/>

tablealign="

border="

产品ID<

产品名称<

购买数量<

单价<

总价<

处理<

for(Iterator<

it=items.iterator();

it.hasNext();

){

CartItemci=it.next();

%=ci.getProduct().getId()%>

%=ci.getProduct().getName()%>

text"

size=3name="

%="

+ci.getProduct().getId()%>

%=ci.getCount()%>

onkeypress="

if(event.keyCode<

45||event.keyCode>

57)event.returnValue=false;

onchange="

document.forms[0].submit()"

%=ci.getProduct().getPrice()%>

%=ci.getProduct().getPrice()*ci.getCount()%>

action=delete&

删除<

tdcolspan=3align="

right"

所有商品总价格为:

tdcolspan=3>

%=c.getTotalPrice()%>

--<

javascript:

修改<

tdcolspan=6align="

清空购物车<

下单<

ptarget="

view_window"

现在时间:

%

response.setHeader("

refresh"

"

60"

out.println(newDate().toLocaleString());

三、实验心得与感受

这次实验总体上进行的相对比较顺利,但是也出现过一些问题。

做网页提示的时候一开始总会出现不提示的情况,后来把show改成了alert解决了问题。

在插入图片时出现过图片不能正常添加的情况,在各个文件夹中插入图片都不能解决,后来发现可以直接在Myeclipse中粘贴,问题得到了解决。

通过实验我发现,jsp语言很有趣很有意思,并且弥补了html的很多问题和缺点,方便又快捷。

本次实验我直接延续了上次实验的主题,自己选的主题很有自主性,做起来也得心应手一些。

在制作的过程中遇到问题也会很烦恼,但在制作完成之后就会很有成就感。

通过这次实验,我继续提高了分析问题,解决问题的能力,也在试验中掌握jsp和动态网页编写的技巧,同时也复习了java的内容,可谓一举三得,也为以后课程的学习打下了良好的基础和铺垫。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 自然景观

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1