jsp获取下拉框组件的值

jsp获取下拉框组件的值

1.首先,写一个带有下拉框的前台页

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10 <form action="request3.jsp" method="post">
11   来自的国家<br/>
12   <select name="country">
13     <option value="中国">中国</option>
14     <option value="美国">美国</option>
15     <option value="俄罗斯">俄罗斯</option>
16   </select>
17   <br/>
18   <input type="submit" />
19 </form>
20 </body>
21 </html>

2.写一个处理页获取下拉框组件的值

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <title>Insert title here</title>
 8 </head>
 9 <body>
10   <%
11   request.setCharacterEncoding("utf-8");
12    String national = request.getParameter("country");
13   out.println(national);
14   
15   %>
16 </body>
17 </html>

 

posted @ 2018-09-01 15:07  silent_fall  阅读(7618)  评论(0编辑  收藏  举报