Jsp code and jsp Summary

Source: Internet
Author: User

 

Jsp code statistics on web page views

 

<A href = "3G. jsp"> 3G </a>

<A href = "Java. jsp"> Java </a>

<%

Object obj = application. getAttribute ("count ");

If (obj = null ){

Integer count = 1;

Application. setAttribute ("count", count );

} Else {

Integer count = (Integer) obj;

Count ++;

Application. setAttribute ("count", count );

}

%>

<H3> the number of visits to the home page is:

<% = Obj. toString () %>

 

PageContext object

 

L pageContext object is the most important object in JSP technology. It represents the running environment of JSP pages. This object not only encapsulates references to other 8 hidden objects, it is a domain object and can be used to save data. In addition, this object also encapsulates some common operations that are often involved in web development, such as introducing and redirecting other resources and retrieving attributes in other domain objects.

 

L use pageContext to obtain other objects

 

L The getException method returns the exception implicit object.

 

L The getPage method returns the page implicit object.

 

L The getRequest method returns the request implicit object.

 

L The getResponse method returns the response implicit object.

 

L The getServletConfig method returns an implicit config object.

 

L The getServletContext method returns the application implicit object.

 

L The getSession method returns the implicit session object.

 

L The getOut method returns an out implicit object.

 

 

L pageContext as the domain object

 

L pageContext object Method

 

L public void setAttribute (java. lang. String name, java. lang. Object value)

 

L public java. lang. Object getAttribute (java. lang. String name)

 

L public void removeAttribute (java. lang. String name)

 

L The pageContext object also encapsulates methods for accessing other domains

 

L public java. lang. Object getAttribute (java. lang. String name, int scope)

 

L public void setAttribute (java. lang. String name, java. lang. Object value, int scope)

 

L public void removeAttribute (java. lang. String name, int scope)

 

L Represents constants of various domains

 

L PageContext. APPLICATION_SCOPE

 

L PageContext. SESSION_SCOPE

 

L PageContext. REQUEST_SCOPE

 

L PageContext. PAGE_SCOPE

 

L findAttribute method (* focus on finding attributes in each domain)

 

L introduce and redirect to other resources

 

L The PageContext class defines a forward method and two include methods to simplify and replace the RequestDispatcher. forward method and include method respectively.

 

L if the resource received by the method starts with "/", "/" indicates the current web application.

 

L JSP tag

 

L JSP tags are also called Jsp Action elements. They are used to provide business logic functions on JSP pages, avoiding the difficulty of maintaining Jsp pages by writing java code directly on JSP pages.

 

 

L common JSP labels

 

L <jsp: include> label

 

L <jsp: forward> label

 

L <jsp: param> label

 

 

 

 

L <jsp: include> label

 

L The <jsp: include> label is used to insert the output content of another resource into the output content of the current JSP page. This introduction method during JSP page execution is called dynamic introduction.

 

L Syntax:

 

L <jsp: include page = "relativeURL | <% = expression %>" flush = "true | false"/>

 

L

 

L The page attribute is used to specify the relative path of the introduced resource. It can also be obtained by executing an expression.

 

L flush attribute specifies whether to refresh the output content of the current JSP page to the client before inserting the output content of other resources.

 

L <jsp: include> comparison with include commands

 

L The <jsp: include> tag is dynamically introduced. The two jsp pages involved in the <JSP: include> tag are translated into two servlets, the contents of the two servlets are merged during execution.

 

L The include command is statically introduced. The two JSP pages involved will be translated into a servlet, whose content is merged at the source file level.

 

L whether it is the <jsp: include> label or the include command, they will combine the content of the two JSP pages and output them. Therefore, do not duplicate the HTML global architecture labels on these two pages, otherwise, the content output to the client will be a messy HTML document.

 

L <jsp: forward> label

 

L <jsp: forward> label is used to forward requests to another resource.

 

L Syntax:

 

L <jsp: forward page = "relativeURL | <% = expression %>"/>

 

L The page attribute is used to specify the relative path of the resource to which the request is forwarded. It can also be obtained by executing an expression.

 

L <jsp: param> label

 

L when you use the <jsp: include> and <jsp: forward> labels to introduce or forward requests to other resources, you can use the <jsp: param> label to pass parameters to this resource.

 

L Syntax 1:

 

L <jsp: include page = "relativeURL | <% = expression %>">

 

L <jsp: param name = "parameterName" value = "parameterValue | <% = expression %>"/>

 

L </jsp: include>

 

L syntax 2:

 

L <jsp: forward page = "relativeURL | <% = expression %>">

 

L <jsp: param name = "parameterName" value = "parameterValue | <% = expression %>"/>

 

L </jsp: include>

 

L The name attribute of the <jsp: param> label is used to specify the parameter name, and the value attribute is used to specify the parameter value. You can use multiple <jsp: param> tags in the <jsp: include> and <jsp: forward> tags to pass multiple parameters.

 

 

 

 

 

L key points

 

L until now, web development has been exposed to four domain objects, which are the focus of web Learning and the knowledge points frequently investigated by the written examination.

 

L pageContext (called the page field) // the current page

 

L request (called request domain) // request

 

L session (called session domain)

 

L servletContext (called application domain)

 

Author qiwancong

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.