在java中如何把下拉列表框中的值获取?jsp页面跳转到servlet里面,在servlet里获值!
3个回答
展开全部
<body>
<form action="/day05/servlet/RequestDemo2" method="post">
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
性别:
<input type="radio" name="gender" value="male">男
<input type="radio" name="gender" value="female">女<br/>
所在地:
<select name="city">
<option value="beijing">北京</option>
<option value="shanghai">上海</option>
<option value="changsha">长沙</option>
</select>
<br/>
爱好:
<input type="checkbox" name="likes">唱歌
<input type="checkbox" name="likes">跳舞
<input type="checkbox" name="likes">篮球<br/>
备注:
<textarea rows="6" cols="60" name="description"></textarea><br/>
大头照:<input type="file" name="image"><br/>
<input type="hidden" name="id" value="12345">
<input type="submit" value="提交">
</form>
public class RequestDemo2 extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String value = request.getParameter("username");
if(value!=null&&!value.trim().equals("")){
System.out.println(value);
}
System.out.println("------------------------------");
Enumeration<String> e = request.getParameterNames();
while(e.hasMoreElements()){
String name = e.nextElement();
value = request.getParameter(name);
System.out.println(name + "="+value);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
<form action="/day05/servlet/RequestDemo2" method="post">
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
性别:
<input type="radio" name="gender" value="male">男
<input type="radio" name="gender" value="female">女<br/>
所在地:
<select name="city">
<option value="beijing">北京</option>
<option value="shanghai">上海</option>
<option value="changsha">长沙</option>
</select>
<br/>
爱好:
<input type="checkbox" name="likes">唱歌
<input type="checkbox" name="likes">跳舞
<input type="checkbox" name="likes">篮球<br/>
备注:
<textarea rows="6" cols="60" name="description"></textarea><br/>
大头照:<input type="file" name="image"><br/>
<input type="hidden" name="id" value="12345">
<input type="submit" value="提交">
</form>
public class RequestDemo2 extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String value = request.getParameter("username");
if(value!=null&&!value.trim().equals("")){
System.out.println(value);
}
System.out.println("------------------------------");
Enumeration<String> e = request.getParameterNames();
while(e.hasMoreElements()){
String name = e.nextElement();
value = request.getParameter(name);
System.out.println(name + "="+value);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
展开全部
<body>
<form action="/day05/servlet/RequestDemo2" method="post">
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
性别:
<input type="radio" name="gender" value="male">男
<input type="radio" name="gender" value="female">女<br/>
所在地:
<select name="city">
<option value="beijing">北京</option>
<option value="shanghai">上海</option>
<option value="changsha">长沙</option>
</select>
<br/>
爱好:
<input type="checkbox" name="likes">唱歌
<input type="checkbox" name="likes">跳舞
<input type="checkbox" name="likes">篮球<br/>
备注:
<textarea rows="6" cols="60" name="description"></textarea><br/>
大头照:<input type="file" name="image"><br/>
<input type="hidden" name="id" value="12345">
<input type="submit" value="提交">
</form>
public class RequestDemo2 extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String value = request.getParameter("username");
if(value!=null&&!value.trim().equals("")){
System.out.println(value);
}
System.out.println("------------------------------");
Enumeration<String> e = request.getParameterNames();
while(e.hasMoreElements()){
String name = e.nextElement();
value = request.getParameter(name);
System.out.println(name + "="+value);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
<form action="/day05/servlet/RequestDemo2" method="post">
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
性别:
<input type="radio" name="gender" value="male">男
<input type="radio" name="gender" value="female">女<br/>
所在地:
<select name="city">
<option value="beijing">北京</option>
<option value="shanghai">上海</option>
<option value="changsha">长沙</option>
</select>
<br/>
爱好:
<input type="checkbox" name="likes">唱歌
<input type="checkbox" name="likes">跳舞
<input type="checkbox" name="likes">篮球<br/>
备注:
<textarea rows="6" cols="60" name="description"></textarea><br/>
大头照:<input type="file" name="image"><br/>
<input type="hidden" name="id" value="12345">
<input type="submit" value="提交">
</form>
public class RequestDemo2 extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String value = request.getParameter("username");
if(value!=null&&!value.trim().equals("")){
System.out.println(value);
}
System.out.println("------------------------------");
Enumeration<String> e = request.getParameterNames();
while(e.hasMoreElements()){
String name = e.nextElement();
value = request.getParameter(name);
System.out.println(name + "="+value);
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-06-16
展开全部
如果jsp页面是form提交的话,直接在后台 request.GerParameter()获取便可以啊!获取<select name="name_a" >name便可以啊。 不行蛮
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |