Related information:
"21-Day Learning Java Web Development"
Get a map that encapsulates all parameter values
1. Obtain the map object that encapsulates all the parameter values by using the Getparametermap () method of the Request object.
2. The Map object allows you to obtain the parameter values for the specified parameter.
requestform5.jsp
1 <%@ Page Language="Java"ContentType="text/html;charset=gb2312" %>2 <HTML>3 <Head>4 <title>Form</title>5 </Head>6 <Body>7 <formAction= "requestdemo5.jsp"Method= "POST">8User name:<inputtype= "text"name= "username"/><BR>9User password:<inputtype= "Password"name= "UserPassword"/><BR>Ten Favorite Sports: One <inputtype= "checkbox"name= "Sport"value= "Pingpang">Table Tennis A <inputtype= "checkbox"name= "Sport"value= "Badketball">Basketball - <inputtype= "checkbox"name= "Sport"value= "Football">Football<BR> - <inputtype= "Submit"value= "Submit"> the </form> - </Body> - </HTML>
View Code
requestdemo5.jsp
1 <%@ Page Language="Java"ContentType="text/html;charset=gb2312"Import="java.util.*" %>2 <HTML>3 <Head>4 <title>Use the Request object to get a map that encapsulates all parameter values</title>5 </Head>6 <Body>7 <%--A map that encapsulates all parameter values through the Getparametermap of the request object--%> 8 <% 9 Map<String, String[]>Mapparamter=Request.getparametermap ();//a map with parameter values for a sealed deviceTen String[] strUserName= (String[]) Mapparamter.get ("username");//get the username parameter value One Out.println ("User name:"+strusername[0]+"<br>");//Print output username parameter values A String[] strpassword= (String[]) Mapparamter.get ("UserPassword");//get Suerpassword parameter value - Out.println ("User password:"+strpassword[0]+"<br>");//print output UserPassword parameter values - String[] Strsport= (String[]) Mapparamter.get ("Sport");//get the sport parameter values the Out.println ("Favorite Sports:"); - for(StringSport:strsport) { - out.println (sport);//traverse Print Output Sport parameter values - } + %> - </Body> + </HTML>
View Code
Java-jsp the request of the built-in object to get a map that encapsulates all parameter values