JSP built-in objects objects --request

Requset common method

Note: Just use IEDA, may not request object method code hints. We need to add to Tomcat lib folder under the File-> Project Structure-> Libraries years.

But also that, when the Chinese pass some parameters may be garbled, you can use the following code to solve

<Request.setCharacterEncoding% ( "UTF-. 8");%> // solve the Chinese garbled

 

1.getParameter

When passing a parameter to another page:

<table>
        <tr>
            <td>用户名:<input type="text" name="Id"></td>
            <td>密码:<input type="password" name="pwd"></td>
            <td><input type="submit" value="登录"></td>
        </tr>
    </table>

GetParameter can be received, as follows

< H1 > Welcome <% = request.getParameter ( " Id " ) %> </ h1 > // where Id is the user name input box of name

 

2.getParameterValues

This receiving method is an array

<tr>
            <td><input type="checkbox" name="favorite" value="篮球"></td>
            <td><input type="checkbox" name="favorite" value="足球"></td>
            <td><input type="checkbox" name="favorite" value="排球"></td>
</tr>
<%
    String[] favorites=request.getParameterValues("favorite");
%>

 

3.setAttribute和getAttribute

<% 
    Request.setAttribute ( " Name " , " Joe Smith " ); // save the attribute named Name, content Zhang 
    the request.getAttribute ( " Name " ); // takes a value of named Name
 %>

 

Behind a few people can be output directly to the page to see jsp expression, no arguments.

Guess you like

Origin www.cnblogs.com/lbhym/p/11587202.html