点餐系统

以下为创建页面的顺序:

 

注册界面(zhuye.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<form action="zhuye2.jsp" method="post">

<h1 > 欢迎光临!</h1>

请输入您的用户名:<input type="text" name="name"><br>

请输入您的密码:<input type="password" name="pass"><br><br>

<input type="submit" value="注册">&nbsp;<input type="reset" value="重置"> 

<%

String name=request.getParameter("name");   //获取name的值

if(name==null)

	name="";

else

	session.setAttribute("name", name);     //将用户名的信息保存到关键字为name中

%>

</form>
</body>
</html>

 

点餐界面(diancan.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="jiesuan.jsp" method="post">
<h1>菜品</h1>
<input type="checkbox" name="cai" value="鸭肠15元">鸭肠15元<br>
<input type="checkbox" name="cai" value="毛肚40.5元">毛肚40.5元<br>
<input type="checkbox" name="cai" value="牛肉48.3元">牛肉48.3元<br>
<input type="checkbox" name="cai" value="山药20元">山药20元<br>
<input type="checkbox" name="cai" value="小菜15.5元">小菜15.5元<br>
<input type="submit" value="提交">&nbsp;<input type="reset" value="重置">

</form>
</body>
</html>

diancan2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String order[]=request.getParameterValues("data");
  if(order!=null)
  {
  StringBuffer str=new StringBuffer();
  for(int k=0;k<order.length;k++)
  {
  str.append(order[k]+"<br>");
  }
  session.setAttribute("order",str);
  }
 
%>

</body>
</html>

diancan3.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>ss
<body>
<%! public String ss(String s) 
{
try{
byte[] bb=s.getBytes("iso-8859-1");
s=new String(bb);
}catch(Exception e)
{   }
return s;
}
%>

</body>
</html>

 

结算界面(jiesuan.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<body bgcolor="f0fff0">
<%  String username=(String)session.getAttribute("name");
if(username==null||username.length()==0)
{   out.print("返回到输入姓名"); } %>
<%StringBuffer order=(StringBuffer)session.getAttribute("order");
String order1=new String(order);
double sum=0;
String[] price=order1.split("[^0123456789.]");
if(price!=null)
{   for(String item:price)
{   try{  sum=sum+Double.parseDouble(item);
}catch(NumberFormatException e2)
{  } } }
%>  <br><br><%=handleStr(username) %>点的餐:<br>
<%=handleStr(order1) %><br>
总付款:<%=sum %>

</body>
</html>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 简单的对比

request.getParameter用的比较多,相对熟悉

request.getParameterValues(String   name)是获得如checkbox类(名字相同,但值有多个)的数据。   接收数组变量 ,如checkobx类型     
request.getParameter(String   name)是获得相应名的数据,如果有重复的名,则返回第一个的值 . 接收一般变量 ,如text类型

1. 三个名字相同的text标签

<input type="text" name="test" value="1" /> 
<input type="text" name="test" value="2" /> 
<input type="text" name="test" value="3" />

 

request.getParameterValues("test")   ----------------- [1, 2, 3]

request.getParameter("test")             ------------------ 1
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

·惊鸿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值