JSP action--jsp There are three ways to stare

Source: Internet
Author: User
Tags html comment java se

First, JSP action

Actions are special tokens that enable the implementation of multiple lines of Java code through an action tag. Ability to insert files dynamically, Reuse JavaBean components, guide and have a page, and more.

Unlike the action element and the instruction element, the action element is run dynamically at the client request and may be run once per client request, while the instruction element is compiled and run at compile time, and it is compiled only once.

<jsp:useBean>

The Usebean action is used to create a reference and embed an existing bean component in a JSP.

Jsp:usebean>

The –usebean action is used to create a reference and embed an existing bean component in a JSP.

Syntax for –usebean:

<jsp:usebean id= "Beanname" class= "Beanclass" scope= "Page|request|session|application"/>

For example, <jsp:usebean id= "book" class= "Com.web.beans.Book" scope= "page"/>

At run time, the Web container checks to see if the JavaBean object already exists, assuming that the existing JavaBean object exists, and instead generates a new JavaBean object. Relative to:

<% Com.web.beans.Book Book=null;

if (Pagecontext.getattribute ("book") ==null) {

Book=new Com.web.beans.Book ();

Pagecontext.setattribute ("book", book);

}else{

book= (book) Pagecontext.getattribute (The "book");

}

%>

I JSP implementation <jsp:usebean id= "book" class= "Com.csdn.beans.Book" scope= "Session"/>

II Java Code Book book=session.getattribute ("book");

If (book==null) {

Book Book=new book ();

Session.setattribute ("book", book);

}

Return Book;

The above I II these two functions are the same

<jsp:setProperty>

The SetProperty action is used to set the value of the property of the bean specified in Usebean. The SetProperty action specifies the name of the JavaBean, the property name, the property value, and the number of parameters that are used to assign the attributes to the bean.

Syntax for setproperty:

<jsp:setproperty name= "Beanalias"
Property= "PropertyName" value= "value"

Param= "Parameter"

/>

Out.println (Bean object. getxxxx ()); Features with output

<jsp:setproperty name= "book" property= "Name" value= "Java se programming explaining"/>
Equivalent to <%book.setname ("Java se Programming explaining");%>

(2) <jsp:setproperty name= "book" property= "Name" param= "BookName" > Assigns a value to the Name property in JavaBean with the value of the parameter BookName in the Request object. Equivalent to
<%book.setname (Request.getparameter ("BookName"))%>

(3) <jsp:setproperty name= "book" property= "Name" >
The name of the parameter in the Request object is the same as the property name in JavaBean. Equivalent to <%book.setname (Request.getparameter ("name"))%>

The asterisk (*) character can be used to specify all of the Bean's properties.

<jsp:setproperty name= "book" property= "*"/>

<jsp:include>

The include action is used to merge the contents of other HTML pages or JSP pages into the current page, or to insert the files in the current page.

Include action with no parameters:

<jsp:include page= "Weburl" flush= "true"/>

Include action with the number of parameters:

<jsp:include page= "Weburl" flush= "true" >

<jsp:param name= "paramname" value= "Paramvalue"/>

<jsp:include>

Two, JSP has three kinds of gaze way

HTML gaze (output gaze): The gaze can be seen when the client is viewing the source code. Like what

<!--this was an HTML comment.it would show up int the response. -

JSP page gaze (hidden gaze): refers to the gaze although written in the JSP program, but not sent to the customer, so when the client view the source code can not see the gaze. This gaze is ignored when the JSP is compiled.

<%--this is a JSP comment.it'll only being seen in JSP code--%>

Java gaze: Can only be out of the Java Code area today, do not agree to directly out of the page today. Single Gaze/* Multi line Gaze */

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.