1, the overview of the JSP specification defines a series of standard actions, the Web container is implemented according to the specification, can parse and execute the standard action. The standard action uses the standard XML syntax, which seems to be more intuitive, and here's a structural example:
<jsp:action_name attribute1="value1" attribute2="value2"></jsp:acion_name>
In the above code, Action_name represents the name of a standard action, while attribute1 and Attribute2 are several properties of the standard action.
2, three commonly used standard action 2.1 Forwardforward action, used in the JSP page for request forwarding, the following code example:
<jsp:forward page="loginSuccess.jsp"></jsp:forward>
The above code forwards the request to the Loginsuccess.jsp page, similar to calling RequestDispatcher's forward method in the servlet for request forwarding. That is, in the JSP page<jsp:forward page= "loginsuccess.jsp" ></jsp:forward> and <% Request.getrequestdispatcher (" Loginsuccess.jsp "). Forward (request, response); %> is the same effect.
The page that contains the action is forwarded to the LOGINSUCCESS.JSP page when you access it.
2.2 Include such as:
<jsp:include page="head.jsp"></jsp:include>
The Include action indicates that a JSP page is
Dynamic Inclusion, which is slightly different from the static inclusions in JSP directives. Dynamic inclusion, which is to access the contained pages during run time, and merges the response results with the response results of the containing page, resulting in a final response. The Include method, similar to calling RequestDispatcher in a servlet, is included.
Static inclusion differs from include directives in that static inclusions occur during the translation phase, and the included JSP files do not generate Java classes, but are included in the Java class of the principal file after translation, that is, the static inclusion will eventually only generate a Java class. Dynamically included, the respective JSP pages generate their own Java classes, but the results of the final response are merged.
2.3 Paramparam actions are often used as sub-actions of forward and include actions to pass parameters. The following code example:
<jsp:forward page="copyright.jsp">
<jsp:param name="author" value="zhangsan"/>
</jsp:forward>
<jsp:include page="head.jsp">
<jsp:param name="time" value="2018-01-30"/>
</jsp:include>
The code above uses Param to pass parameters for the forward and include actions, and the parameters are passed as request parameters. If the parameter time is passed for head.jsp, then the head.jsp page can be displayed in a way similar to <%=request.getparameter ("Time")%>.
3, JavaBean related to the standard action of the so-called JavaBean, is the Java language description of the software component model, is actually a javase class, the class follows a certain specification:
- Must be a public class
- Must have a non-parametric public construction method
- The method for returning a property is GetXXX
- To set a property by Setxxx
In JSP, there are three standard actions related to JavaBean, because now more use of Jstl, El expressions, so these standard actions are less used.
3.1 Usebean
<jsp:useBean id="" class="" scope="" ></jsp:useBean>
Using the Usebean standard action, you can get (or create) a {class} class named {ID} within the scope {scope}, which can be page, request, session, application.
<jsp:useBean id="zhangsan" class="com.learn.Person" scope="request" ></jsp:useBean>
As the above example means: Call Request.getattribute ("Zhangsan"), if there is no Zhangsan, then call the person's parameterless construction method to create, and setattribute ("Zhangsan", New person ( ))。
3.2 SetProperty
<jsp:setProperty name="" property="" param|value="" />
The setproperty is used to assign the properties of the JavaBean object to replace the Setxxx method. Among them:
- Name indicates the ID value of the JavaBean object
- property represents the attribute name of the JavaBean object
- param if you want to inject a value that is a request parameter, use the Param property
- Value if the value you want to inject is a constant, use the Value property
3.3 GetProperty
<jsp:getProperty name="" property="" />
GetProperty is used to call the JavaBean object's GetXXX method to get the corresponding property value, where:
- Name indicates the ID value of the JavaBean object
- property represents the attribute name of the JavaBean object
4, the other more than the common JSP standard action, there are a part of the use of less, if you are interested to know for themselves.
5, written in the back of the words but now, who still use what JSP standard action ah???
[] JSP standard action