JSP built-in objects request and response

Source: Internet
Author: User
Tags port number server port

JSP built-in object Request object

The client's request information is encapsulated in a request object to understand the customer's needs and then respond. It is an instance of the HttpServletRequest class.

Serial Number Method description

1 Object getattribute (String name) returns the property value of the specified property

2 enumeration Getattributenames () returns an enumeration of all available property names

3 String getcharacterencoding () returns the character encoding method

4 int Getcontentlength () returns the length of the requested body (in bytes)

5 String getContentType () Gets the MIME type of the requested body

6 ServletInputStream getInputStream () gets the binary stream of a row in the request body

7 string GetParameter (string name) returns the parameter value of the specified parameter of name

8 enumeration Getparameternames () returns an enumeration of the available parameter names

9 string[] Getparametervalues (String name) returns an array of all values containing the parameter name

A String Getprotocol () returns the type and version number of the protocol used for the request

One String Getscheme () returns the plan name for the request, such as: Http.https and FTP

A String getServerName () returns the server host name that accepts the request

int Getserverport () returns the port number used by the server to accept this request

BufferedReader Getreader () returns the decoded request body

String getremoteaddr () Returns the client IP address that sent this request

String Getremotehost () returns the client host name that sent the request

void setattribute (String key,object obj) Set property value for property

A string Getrealpath (string path) returns the true path of a virtual path

  <%@ page contenttype= "text/html;charset=gb2312"%><%request.setcharacterencoding ("gb2312");%> < HTML > < Head> < Title>request Object _ example 1</title> </head> < body bgcolor= "#FFFFF0" > < form ACTI on= "" method= "POST" > < input type= "text" name= "qwe" > < input type= "submit" value= "Submit" > </form> request mode: <%=request.getmethod ()%>< br> requested resource:<%=request.getrequesturi ()%>< br> Request Protocol:< Request.getprotocol ()%>< br> requested file name:<%=request.getservletpath%>< () br> ip:< the requested server Request.getservername ()%>< br> request Server Port:<%=request.getserverport ()%>< br> client IP address:< REQUEST.GETREMOTEADDR ()%>< br> client host name:<%=request.getremotehost ()%>< br> form submission Value:< Request.getparameter ("Qwe")%>< br> </body> </html> <%@ page contenttype= "text/html;charset= gb2312 "%> <%request.setcharacterencoding (" gb2312 ");%> <%@ page ImpOrt= "Java.util.Enumeration"%> < html> < Head> < Title>request Object _ example 2</title> </head> & Lt Body bgcolor= "#FFFFF0" > < form action= "" method= "POST" > User name:< input type= "text" name= "username" > Password:< i Nput type= "text" name= "Userpass" > < input type= "submit" value= "enter" > </form> <% String str= ""; if (Request.getparameter ("username")!=null && request.getparameter ("Userpass")!=null) {Enumeration enumt = Request.getparameternames (); while (Enumt.hasmoreelements ()) {str=enumt.nextelement (). toString (); Out.println (str ":" Request.getparameter (str) " < br> "); }%> </body> </html> <%@ page contenttype= "text/html;charset=gb2312"%> <%REQUEST.SETCHARACTE Rencoding ("gb2312");%> < html> < Head> < Title>request Object _ example 3</title> </head> < body b Gcolor= "#FFFFF0" > < form action= "" method= "post" > Good at:< input type= "checkbox" Name= "CB" value= "ON1" >VC < INput type= "checkbox" Name= "CB" value= "ON2" >java < input type= "checkbox" Name= "CB" value= "ON3" >delphi < input type= "checkbox" Name= "CB" value= "ON4" >vb < br> < input type= "submit" value= "enter" Name= "Qwe" > </form> <% if (Request.getparameter ("Qwe")!=null) {for (int i=0;i< request.getparametervalues ("CB"). Length;i) { OUT.PRINTLN ("CB" I ":" Request.getparametervalues ("CB") [i] "< br>");} Out.println (Request.getparameter ("qwe")); }%> </body> </html>

JSP built-in object Response object

The Response object contains information about the response to a customer request, but it is rarely used directly in the JSP. It is an instance of the HttpServletResponse class.

Serial Number Method description

1 String getcharacterencoding () returns what character encoding is used for the response

2 Servletoutputstream Getoutputstream () returns a binary output stream of the response

3 PrintWriter getwriter () returns an object that can output characters to the client

4 void setcontentlength (int len) set Response head length

5 void setContentType (String type) sets the MIME type of the response

6 Sendredirect (java.lang.String location) requests to redirect clients

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.