<%@ page contentType="text/html;charset=gbk"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.valueBean.GoodsSingle" %>
<%!
static ArrayList goodsList=new ArrayList();
static{
String[] name={"玩具车","积木","绘本","故事机"};
String[] product={"儿单电动车 宝宝婴幼儿玩具车 可坐人 电瓶四轮童车 遥控越野吉普车","木制大积木 宝宝早教益智玩具 立体积木","绘本不一样的卡梅拉 第一季 第二季 畅销书 动漫全套","故事机 早教机 MP3播放器 可充电 可下载 可遥控"};
float[] price={800f,78f,260f,120f};
for(int i=0;i<4;i++){
GoodsSingle single=new GoodsSingle();
single.setName(name[i]);
single.setProduct(product[i]);
single.setPrice(price[i]);
single.setNum(1);
goodsList.add(i,single);
}
}
%>
<%
session.setAttribute("goodsList",goodsList);
response.sendRedirect("show.jsp");
%>
--------------------
<%@ page contentType="text/html;charset=gbk"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.valueBean.GoodsSingle" %>
id="myCar" class="com.toolsBean.ShopCar" scope="session"/>
<%
ArrayList buyList=myCar.getBuyList();
float total=0;
int count=0;
%>
<table width="450" border="1" rules="none" cellspacing="0" cellpadding="0">
<tr height="50"><td colspan="7" align="center"><font color="blue">您的购物车font>td>
<tr align="center" height="30" bgcolor="lightgrey">
<td width="25%">名称td>
<td>图片td>
<td>价格(元)td>
<td colspan="3">数量td>
<td>总价(元)td>
tr>
<% if(buyList==null||buyList.size()==0){ %>
<tr height="100"><td colspan="7" align="center">您的购物车为空!td>
<%
}
else{
for(int i=0;i name=single.getName();
float price=single.getPrice();
int num=single.getNum();
float money=price*num;
total+=money;
if(num!=1)
count+=num;
else
count++;
%>
<tr align="center" height="50">
<td><%=name%>td>
<td>
<%
int j;
ArrayList goodsList=(ArrayList)session.getAttribute("goodsList");
for(j=0;j{
GoodsSingle temp=(GoodsSingle)goodsList.get(j);
if(temp.getName().equals(name)){
break;
}
}
%>
<img src="images/<%="goods"+j%>.jpg" width="100">
td>
<td><%=price%>td>
<td width="30" align="right">
<form action="docar.jsp?action=remove&name=<%=single.getName()%>" method="post">
<input type="submit" value="-" style="border:none;">
form>
td>
<td width="30">
<%=num%>
td>
<td width="30" align="left">
<form action="docar.jsp?action=addbuy&name=<%=single.getName()%>" method="post">
<input type="submit" value="+" style="border:none;">
form>
td>
<td><%=money%>td>
tr>
<%
}
}
%>
<tr height="50" align="center"><td colspan="7"><font color="red">购物车中共有<%=count %>件商品,结算:<font size="5">¥<%=total%>元font>font>td>tr>
<tr height="50" align="center">
<td colspan="2">
<form action="show.jsp" method="post">
<input type="submit" value="继续购物">
form>
td>
<td colspan="5">
<form action="docar.jsp?action=clear" method="post">
<input type="submit" value="清空购物车">
form>
td>
tr>
table>
----------------------------
<%@ page contentType="text/html;charset=gbk"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.valueBean.GoodsSingle" %>
<% ArrayList goodsList=(ArrayList)session.getAttribute("goodsList"); %>
<table width="450" border="1" rules="none" cellspacing="0" cellpadding="0">
<tr height="50"><td colspan="3" align="center"><font color="blue">欢迎您光临玩具店哦!font>td>tr>
<tr align="center" height="30" bgcolor="lightgrey">
<td>名称td>
<td>图片td>
<td>价格(元)td>
tr>
<% if(goodsList==null||goodsList.size()==0){ %>
<tr height="100"><td colspan="4" align="center">没有商品可显示!td>
<%
}
else{
for(int i=0;i
<tr height="50" align="center">
<td><a href="goods.jsp?goods=<%=i %>" style="text-decoration:none"><%=single.getName()%>a>td>
<td><a href="goods.jsp?goods=<%=i %>"><img src="images/<%="goods"+i%>.jpg" border="0" width="100">a>td>
<td><%=single.getPrice()%>td>
tr>
<%
}
}
%>
<tr height="70">
<td align="center" colspan="3">
<form action="shopcar.jsp" method="post">
<input type="submit" value="查看购物车">
form>
td>
tr>
table>
----------
package com.toolsBean;
import java.util.ArrayList;
import com.toolsBean.MyTools;
import com.valueBean.GoodsSingle;
public class ShopCar {
private ArrayList buyList=new ArrayList();
public ArrayList getBuyList() {
return buyList;
}
public void addItem(GoodsSingle single){
if(single!=null){
if(buyList.size()==0){
GoodsSingle newGoods=new GoodsSingle();
newGoods.setName(single.getName());
newGoods.setProduct(single.getProduct());
newGoods.setPrice(single.getPrice());
newGoods.setNum(single.getNum());
buyList.add(newGoods);
}
else{
int i=0;
for(;iif(newGoods.getName().equals(single.getName())){
newGoods.setNum(newGoods.getNum()+1);
break;
}
}
if(i>=buyList.size()){
GoodsSingle newGoods=new GoodsSingle();
newGoods.setName(single.getName());
newGoods.setPrice(single.getPrice());
newGoods.setNum(single.getNum());
buyList.add(newGoods);
}
}
}
}
public void addItem(String name){
for(int i=0;iif(newGoods.getName().equals(MyTools.toChinese(name))){
newGoods.setNum(newGoods.getNum()+1);
break;
}
}
}
public void removeItem(String name){
for(int i=0;iif(newGoods.getName().equals(MyTools.toChinese(name))){
if(newGoods.getNum()>1){
newGoods.setNum(newGoods.getNum()-1);
break;
}
else if(newGoods.getNum()==1){
buyList.remove(i);
}
}
}
}
public void clearCar(){
buyList.clear();
}
}
---------------------
package com.toolsBean;
import java.io.UnsupportedEncodingException;
public class MyTools {
public static int strToint(String str){
if(str==null||str.equals(""))
str="0";
int i=0;
try {
i=Integer.parseInt(str);
} catch(NumberFormatException e){
e.printStackTrace();
}
return i;
}
public static String toChinese(String str){
if(str==null)
str="";
try {
str=new String(str.getBytes("ISO-8859-1"),"gbk");
} catch (UnsupportedEncodingException e) {
str="";
e.printStackTrace();
}
return str;
}
}
--------
package com.valueBean;
public class GoodsSingle {
private String name;
private String product;
private float price;
private int num;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
}
求解分析javabean中的内容,分析jsp程序内容。程序整体运行过程。
具体哪里不清楚?
jsp页面底层就是servlet,可以通过jstl语法来编写java代码。
Javabean 是为了和 jsp 页面传数据化简交互过程而产生的,jsp页面也可以导入使用javabean,通过类名.属性名的方式来获取对应的属性值。
<% %>内就是可以用来写Java代码的。