该程序共有两个文件 buy.jsp 和show.jsp
文件buy.jsp如下:
<head>
<title>
Doing Some Shoppings
</title>
</head>
<body>
<Script language= "java ">
void fun()
{
var len=document.shop.choice.length;
for(int i=0;i <len;i++)
{
document.shop.choice[i].checked=document.shop.all.checked;
}
}
</Script>
<form name= "shop " action= "show.jsp " method= "post ">
What do you want to buy: <input type= "checkbox " name= "choice " value= "basketball " checked> basketball
<input type= "checkbox " name= "choice " value= "football "> football
<input type= "checkbox " name= "choice " value= "baseball "> baseball
<input type= "checkbox " name= "choice " value= "all " onclick= "fun() "> all
<br> <br>
<input type= "submit " name= "go ">
<input type= "reset " name= "reset ">
</form>
</body>
</html>
文件show.jsp如下:
<html>
<head>
<title>
show the things
</title>
</head>
<body>
<%
for(int i=0;i <3;i++)
{
String names[i]=request.getParameterValues();
}
session.setAttribute( "first ",names[0]);
session.setAttribute( "second ",names[1]);