JSP three major instructions and action tags

Source: Internet
Author: User

JSP three major instructions
A JSP page can have 0-n instructions

1.page---> Most complex: <% @page language= "" ...%>
*pageencoding and ContentType
Pageencoding: Specify the current JSP page encoding, as long as not to lie, there will be no garbled! You need to use pageencoding when the server wants to compile the JSP into. Java
ContentType: It means adding a response header: Content-type, equivalent to Response.setcontenttype ()

*import: Guide package, can appear multiple times
*errorpage and Iserrorpage
ErrorPage: If the current page throws an exception, then which page to forward to, determined by errorpage, the status code is 200
Iserrorpage: Specify page for handling error page! When this property is true, the page is set to a status code of 500, and this page can use the exception in the 9 large built-in objects

<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8" errorpage= "error/error.jsp"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >inta=13/0; %> </body>Import= "java.util.*" pageencoding= "UTF-8" iserrorpage= "true"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >haha, something went wrong! <br/> <%//<%=exception.getmessage ()% > <br/>//<%exception.printstacktrace (Response.getwriter ());% >//of course, the error message will not be displayed directly to the user, will become humane%> </body>View Code

*autoflush and Buffer
AutoFlush: Specifies whether the JSP's output stream is full, if it is automatically refreshed, the default is true, and if False, throws an exception when the buffer is full
Buffer: Specifies the size of the buffers, which defaults to 8KB and does not need to be modified
*iselignored: Whether to ignore the El expression, the default is false, do not ignore, that is, support!
* Basically useless
Language: Specifies the current JSP compiled language type, default to Java
Info: Info
IsThreadSafe: Does the current JSP support concurrent access?
Session: Whether the current page supports session, if False, then the current page is not the session of the built-in object
Extends: Let JSP-generated servlet inherit the class specified by this property

2.include--> static inclusions
* Features similar to RequestDispatcher's include () method
*<% @include%> is done when the JSP is compiled into a Java file, which together generates a Java file and then generates a class!
*requestdispatcher's include () is a method that contains and is comprised of two servlets, or two classes, that simply merge the contents of the response at runtime.
* Role: Decomposition of the page, the use of a combination of methods, so that the unchanging part of a page is a separate JSP, and we only need to deal with the change of the page

<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >Note that file cannot use variables because the variables are in Java code, and the execution of Java code is executed after the program is run.-<body> <%String name= "Guodaxia"; %> <% @include file= "lj.jsp"%> </body>View Code

3.taglib--> Importing Tag libraries
Two properties
>prefix: Specifies the prefix of the tag library in this page! by our own name!
>uri: Specify the location of the tag library
><% @taglib prefix= "pre" uri= "/struts-tags"%> prefix usage <s:text>

JSP Action Tags

JSP Action Tags
The action tags of these jsps are essentially different from the HTML tags.
* Action tag is performed by Tomcat (server) to interpret! As with Java code, it is performed by the server.
*html is executed by the browser!
*<jsp:forward>: Forward! It is the same as the Forwaard method of RequestDispatcher, one is used in servlet, one is used in JSP!

*<jsp:include>: Dynamic inclusion: It is the same as the RequestDispatcher include method, one that is used in the servlet and one that is used in the JSP!
What is the difference between ><% @include%> and <jsp:include>?

*<jsp:param>: It is used as a sub-label for forward and include to pass parameters using

<%@ page language= "Java"Import= "java.util.*" pageencoding= "UTF-8"%><%String Path=Request.getcontextpath (); String BasePath= Request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >String name=request.getparameter ("name"); String Password=request.getparameter ("Password"); Out.write (Name+","+password); %>
View Code

JavaBean Specification:

JavaBean Specification:
1, must have a modulo constructor
2, provide Get/set method, if only get method, then this property is read-only property!
3, attribute: Member with Get/set method, can also have no member, only Get/set method. The name of the property is the Get/set method to remove the previous get/set after the first letter lowercase to get
4, the method name satisfies a certain specification, then it is a property! The read side of a Boolean property can be the start of an IS or a get start

Introspective class-->bean information--the property descriptor--the get/set corresponding to the property method--> can reflect the
Commons-beanutils, which is dependent on introspection complete
* Guide Package
Beanutils.setproperty (Stu, "username", "Guodaxia");
int age=integer.valueof (Beanutils.getproperty (Stu, "age"));
Beanutils.populate (stu, map);

Tags related to JavaBean in JSP
*<jsp:usebean>---> Create or query Beans
*<jsp:usebean id= "user1" class= "Cn.itcast.domain.User" scope= "session"/> Find User1 in session field named Usebean does not exist then create
*<jsp:usebean id= "user1" class= "Cn.itcast.domain.User" scope= "Session"/>
*<jsp:setproperty property= "username" name= "user1" value= "admin"/>
*<jsp:getproperty property= "username" name= "user1"/>

JSP three major instructions and action tags

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.