Wu Yuxiong--JSP-Servlet study notes developed by natural JAVA: request object-get Chinese characters in GET request

<%-- 
    Document   : form
    Created on : 2020-4-11, 23:10:56
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> 收集参数的表单页 </title>
    </head>
    <body>
        <form id="form1" method="get" action="request3.jsp">
            用户名:<br/>
            <input type="text" name="name"><hr/>
            性别:<br/>
            男:<input type="radio" name="gender" value="男">
            女:<input type="radio" name="gender" value="女"><hr/>
            Red:/>br<
            Favorite color:<input type="checkbox" name="color" value="红">
            绿:<input type="checkbox" name="color" value="绿">
            蓝:<input type="checkbox" name="color" value="蓝"><hr/>
            来自的国家:<br/>
            <select name="country">
                <</China>= "China"valueoptionoption>
                <option value="美国">美国</option>
                <option value="俄罗斯">俄罗斯</option>
            </select><hr/>
            <input type="submit" value="提交">
            <input type="reset" value="重置">
        </form>
    </body>
</html>

 

 

<%-- 
    Document   : request3
    Created on : 2020-4-11, 23:39:55
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> 获取包含非西欧字符的GET请求参数 </title>
    </head>
    <body>
        <% 
=rawQueryStrStringGet the query string contained in the request
            // request.getQueryString();
            out.println ( "The original query string is: "  + rawQueryStr +  " <hr /> " );
 // Use URLDecoder to decode the string
             String queryStr = java.net.URLDecoder.decode (
                    rawQueryStr, "UTF-8");
            out.println ( "The decoded query string is: "  + queryStr +  " <hr /> " );
 // The query string is decomposed
             with an ampersand String [] paramPairs = queryStr.split ( " & " );
             for ( String paramPair: paramPairs) {
                out.println ( " Each request parameter name and value pair is: "  + paramPair +  " <br/> " );
                 // Resolve the request parameter name and value
                 with = String [] nameValue = paramPair.split ( " = " ) ;
                out.println (nameValue [ 0 ] +  " The value of the parameter is: " 
                        + nameValue [ 1 ] +  " <hr /> " );
            }
        %>
    </body>
</html>

 

Guess you like

Origin www.cnblogs.com/tszr/p/12683158.html