Jsp object details

Source: Internet
Author: User

1. Out object
It is mainly used to output data of various formats to the client and manage the output buffer on the application server. The base class of the Out object is the javax. servlet. jsp. JspWriter class.

Out Methods:
Out. println (DataType); or out. print (DataType );

Instance:
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
Import = "java. util .*"
%>
<HTML>
<HEAD>
<TITLE> instances used by out objects </TITLE>
</HEAD>
<BODY>
<%
Out. println (new Date (). toLocaleString ());
Out. print ("<BR> ");
Out. print ("test successful ");
%>
</BODY>
</HTML>

2. Request object
Request. setAttribute () and Request. getAttribute () method instances (you can also use forward to establish a Request relationship ):

Home page:

<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
%>
<% @ Include file = "1.jsp" %>
The content you just entered is:
<% = Request. getAttribute ("gr") %>

Introduction page:
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
Import = "java. util .*"
%>
<HTML>
<HEAD>
<TITLE> request object instance </TITLE>
</HEAD>
<BODY>
<%
Request. setAttribute ("gr", "123333 ");
%>
</FORM>
</BODY>
</HTML>

Request. getParameter () Method Instance

Home Page
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
Import = "java. util .*"
%>
<HTML>
<HEAD>
<TITLE> request. getParameter () method using an instance </TITLE>
</HEAD>
<BODY>
<Form method = post action = "2.jsp">
<Input type = "text" NAME = "gr1"> <BR>
<Input type = "text" NAME = "gr2"> <BR>
<Input type = "text" NAME = "gr3"> <BR>
<Input type = "submit" NAME = "submit" value = "submit">
<Input type = "reset" NAME = "reset" value = "clear">
</FORM>
</FORM>
</BODY>
</HTML>

Introduction page
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
%>
The content you just entered is: <BR>
<% = Request. getParameter ("gr1") %> <BR>
<% = Request. getParameter ("gr2") %> <BR>
<% = Request. getParameter ("gr3") %> <BR>

Request. getParameterName () Method Instance

Home Page
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
%>
<HTML>
<HEAD>
<TITLE> request. getParameterName () method using an instance </TITLE>
</HEAD>
<BODY>
<Form method = post ACTION = "2.jsp">
<Input type = "text" NAME = "gr1"> <BR>
<Input type = "text" NAME = "gr2"> <BR>
<Input type = "text" NAME = "gr3"> <BR>
<Input type = "submit" value = "submit">
<Input type = "reset" value = "clear">
</FORM>
</FORM>
</BODY>
</HTML>

Point to page
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
Import = "java. util .*"
%>
The content you just entered is: <BR>
<%
Enumeration e = request. getParameterNames ();
While (e. hasMoreElements ()){
String parameterName = (String) e. nextElement ();
String parameterValue = (String) request. getParameter (parameterName );
Out. print ("parameter name:" parameterName "<BR> ");
Out. print ("parameter content:" parameterValue "<BR> ");
}
%>

Request. getAttributeName () Method Instance

Home page:
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
Import = "java. util .*"
%>
<HTML>
<HEAD>
<TITLE> request. getAttributeName () method using an instance </TITLE>
</HEAD>
<BODY>
<Jsp: include page = "2.jsp" flush =" true "/>
<%
Enumeration e = request. getAttributeNames ();
While (e. hasMoreElements ()){
String attributeName = (String) e. nextElement ();
String attributeValue = (String) request. getAttribute (attributeName );
Out. print ("variable name:" attributeName );
Out. print ("variable content:" attributeValue "<BR> ");
}
%>
</FORM>
</FORM>
</BODY>
</HTML>


Redirection page
<% @ Page language = "java"
ContentType = "text/html; charset = gb2312"
%>
<%
Request. setAttribute ("gr1", "111 ");
Request. setAttribute ("gr2", "222 ");
Request. setAttribute ("gr3", "333 ");
%>

Request. getRemoteAddr () method instance:

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.