First, JSP action
Action is a special tag that enables the effect of multiple lines of Java code implementation through an action tag. You can insert files dynamically, Reuse JavaBean components, guide another page, and so on.
The action element differs from the instruction element in that the action element is executed dynamically at the request of the client and may be executed once each time a client request is performed, and the instruction element is compiled at compile time, and it is compiled only once.
<jsp:useBean>
The Usebean action is used to create the reference and embed the existing bean component in the JSP.
Jsp:usebean>
The –usebean action is used to create the reference and embed the existing bean component in the 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 execution time, the Web container checks whether the JavaBean object already exists, uses the existing JavaBean object if it 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 ("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;
Above the I II these two functions like
<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, property name, property value, and parameters that are used to assign to the Bean's properties.
Syntax for setproperty:
<jsp:setproperty name= "Beanalias"
Property= "PropertyName" value= "value"
Param= "Parameter"
/>
Out.println (Bean object. getxxxx ()); Features that have output
<jsp:setproperty name= "book" property= "Name" value= "Java se programming Intensive"/>
Equivalent to <%book.setname ("Java se Programming Intensive");%>
(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 parameter name 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 the properties of the bean.
<jsp:setproperty name= "book" property= "*"/>
<jsp:include>
An include action is used to merge content from another HTML page or JSP page into the current page, or to insert a file into the current page.
Include action with no parameters:
<jsp:include page= "Weburl" flush= "true"/>
Include actions with parameters:
<jsp:include page= "Weburl" flush= "true" >
<jsp:param name= "paramname" value= "Paramvalue"/>
<jsp:include>
Two, JSP has three kinds of annotation way
HTML comment (output Note): The annotation is visible when the client is viewing the source code. For example
<!--this are an HTML comment.it'll show up int the response. -->
JSP page Comments (hidden annotations): notes that are written in the JSP program but are not sent to the customer, so you cannot see the annotation when the client is viewing the source code. Such annotations are ignored when the JSP is compiled.
<%--this is a JSP comment.it'll only to seen in JSP code--%>
Java annotations: Can only appear in the Java code area, not allowed to appear directly in the page. Single-line Comment */Multiline Comment * *