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: