JSP CHECKBOX

来源:百度知道 编辑:UC知道 时间:2024/05/24 08:51:47
shopping1.jsp

<%@page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>购物车</title>
</head>
<body>
各种肉类大甩卖,一律十块:<br />
<form name="shopping1" method="post" action="shopping1.jsp">
<input type="checkbox" name="猪肉" value="猪肉" /> 猪肉<br />
<input type="checkbox" name="牛肉" value="牛肉" /> 牛肉<br />
<input type="checkbox" name="羊肉" value="羊肉" /> 羊肉<br />
<input type="submit" name="yes" value="提交" /> <input type="reset" name="no" value="取消" /><br />
<a href="shopping2.jsp">买点别的</a> <a href="display.jsp">查看购物车</a>
</form>

checkbox的NAME不能是中文。

不该用文本框,要用输入框滴。

checkbox的写法如下:
<input type="checkbox" name="猪肉" value="猪肉" > 猪肉<br >
<input type="checkbox" name="猪肉" value="牛肉" > 牛肉<br >
<input type="checkbox" name="猪肉" value="羊肉" > 羊肉<br >
像你原来的写法,如果没有选择"猪肉",goods1就为空了.

我在电脑上刚才调试了,是文件编码问题。

<%@page language="java" contentType="text/html;charset=gb2312"%>
<html>
<head>
<title>购物车</title>
</head>
<body>
各种肉类大甩卖,一律十块:<br />
<form name="shopping1" method="post" action="">
<input type="checkbox" name="meat" value="Pork" /> Pork<br />
<input type="checkbox" name="meat" value="Beef" /> Beef<br />