Today, write code encountered a problem, in the JSP page through the form of the Select Tag Value, form submitted to its own page, and then through the Request.getparameter () method to get the value
The test code is as follows (file name: testselect.jsp):
<% @ page language = "java" import = "java.util. *" pageEncoding = "GB18030"%>
<%
request.setCharacterEncoding ("GB18030"); // Add this sentence to solve
String path = request.getContextPath ();
String basePath = request.getScheme () + ": //"
+ request.getServerName () + ":" + request.getServerPort ()
+ path + "/";
// Array that stores the corresponding value of the menu
ArrayList nu = new ArrayList ();
nu.add ("one");
nu.add ("two");
nu.add ("three");
%>
<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.01 Transitional // EN">
<html>
<head>
<base href = "<% = basePath%>">
<title> My JSP 'testselect.jsp' starting page </ title>
</ head>
<body>
Use request.getParameter ("number") method to get the value selected by the drop-down box
<form method = post action = "testselect.jsp"> <!-Submit to yourself->
<select name = number>
<%
for (int i = 0; i <nu.size (); i ++) {
out.print ("<option>" + nu.get (i) + "</ option>");
}
%>
</ select>
<input type = "submit" value = "submit" name = "submit">
</ form>
</ body>
<%
// Get the submitted number and display
String n = (String) request.getParameter ("number");
out.print ("The selected value is:" + n);
%>
</ html>
Run the interface: