如何在JSP中用下拉框和复选框等传参数到Servlet

来源:百度知道 编辑:UC知道 时间:2024/06/19 00:48:54
比如我在JSP上做了一个下拉框:
<select name="level" id="Leve" >
<option value="vip">VIP</option>
<option value="common>COMMON</option>
</select>
或者做了一个复选框:
<input type="checkbox" value="vip" name="Vip" >VIP
<input type="checkbox" value="common" name="Common" >COMMON

我要把我选中的那个项传到form里面action对应的Servlet里面
应该怎么写?麻烦各位高手指点

方法有两种,第一种是自己定一个Servlet,第二种是写个jsp页面来接收。
代码如下:
第一种:
public class Test extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request,response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String danxuan=request.getParameter("level");
String fuxuan1=request.getParameter("Vip");
String fuxuan2=request.getParameter("Common");
下面是你自己的代码。
}

}
如果用这种办法,那么需要配置web.xml。在这个文件里添加如下代码:
<servlet>
<description></description>
<display-name>Test</display-name>
<servlet-name>Test</servlet-name>
<servlet-class>你的包名.Login</servlet-cla