http://localhost:8080/HelloServlets/Hello?Maths=on
Servlet Name =“Hello Servlets” Servlet class =“Hello”
上面传递的URL字符串可以正常工作。但是,尝试从HTML表单传递值,
形成的URL字符串是
http://localhost:8080/HelloServlets/checkbox?Maths=on
然后当然我找不到资源。
遵循HTML表单代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Please add your Details</title>
</head>
<body>
<form action = "Hello" method = "Get" target = "_blank">
<input type = "checkbox" name = "Maths"/>Maths
</br>
<input type = "checkbox" name = "Physics"/>Physics
</br>
</br>
<input type = "submit" value = "Select Subject"/>
</form>
</body>
问题究竟在哪里?
答案 0 :(得分:0)
修改强>
无效的广告代码
</br><!-- not this -->
<br/><!-- try this -->
分组复选框
数据以name=value
对发送。
试试这个:
<input type="checkbox" value="Maths" name="Subject"/>Maths
<input type="checkbox" value="Physics" name="Subject"/>Physics
在servlet中使用:
String[] Subjects = request.getParameterValues("Subject");