JSP three major instructions
A JSP page, you can have a definition of 0~n instructions!
Page–> most complex: Format: <% @page language= "java" info= "xxx" ...%>
- Pageencoding and ContentType:
Pageencoding: It specifies 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 ("Text/html;charset=utf-8");
If two properties only provide one, then the other default is the one that is set.
If none of the two properties are set, the default is ISO
- Import: Guide Package! can appear multiple times
ErrorPage and Iserrorpage
ErrorPage: If the current page throws an exception, which page to forward to, by ErrorPage to specify
Iserrorpage: It specifies whether the current page is an error-handling page! When this property is true, the page will be set to a status code of 500! And this page can use the exception! in 9 large built-in objects
Configuring the error page in Web. xml
404
/error/errorpage.jsp
500
/error/errorpage.jsp
Java.lang.RuntimeException
/index.jsp
- AutoFlush and Buffer
AutoFlush: Specifies whether the JSP output stream buffer is full, 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 normally need to be modified!
- Iselignored: Whether the El expression is ignored, the default value is False, not ignored, that is, support!
- Basically useless:
Language: Specifies the language type of the current JSP compilation and the default value is java.
Info: Info!
IsThreadSafe: Does the current JSP support concurrent access?
Session: Whether the current page supports session, if False, then the current page does not have the session of this built-in Object!
Extends: Let the JSP-generated servlet inherit the class specified by this property!
include–> static inclusions
- Similar to the functionality of the include () method of RequestDispatcher!
- <% @include%> It is done when the JSP is compiled into a Java file! Together they generate a Java (that is, a servlet) file and then generate a class!
- RequestDispatcher's include () is a method that contains and is comprised of two servlets, or two. class! They just merge the content of the response at run time!
- Role: Decomposition of the page, the use of a combination of methods, such a page is a constant part of a separate JSP, and we only need to deal with the change of the page. To implement page reuse
* Unique attribute file
Taglib–> Importing Tag libraries
Prefix: Specifies the prefix of the tag library in this page! by our own name!
URI: Specifies the location of the tag library!
<% @taglib prefix= "s" uri= "/struts-tags"%>
Usage of prefix:
==========================================================
Nine built-in objects
JSP Action Tags (20)
The action tags of these jsps are essentially different from the tags provided by HTML.
* Action tag is performed by Tomcat (server) to interpret! It is executed on the server side, just like Java code!
* HTML is executed by the browser!
*: Forward! It is the same as the forward method of RequestDispatcher, one is used in servlet, one is used in JSP!
*: Contains: It is the same as the RequestDispatcher include method, one is used in the servlet, one is used in the JSP!
<% @include > And what's the difference!
*: It is used as a sub-label for forward and include! Used to pass parameters to forwarded or included pages!
JavaBean
Specifications for JavaBean:
1. You must have a default constructor! (i.e., without reference)
2. Provide the Get/set method, if only get method can also, then this property is read-only property!
3. Attribute: A member with the Get/set method is called a property, and there can be no member, only the Get/set method. The property name is determined by the Get/set Method! Instead of the member name!
4. The method name satisfies a certain specification, then it is the attribute!
A Boolean property whose read method can be the start of an IS, or a get start!
Introspection:
Introspection Class (Introspector) –> Bean information (BeanInfo) –> Property Descriptor (PropertyDescriptor) –> corresponding Get/set of the property I can reflect it!
Commons-beanutils, it is dependent on introspection to complete!
* Guide Package:
Commons-beanutils.jar
Commons-logging.jar
Beanutils.getproperty (Object Bean, String PropertyName)
Beanutils.setproperty (Object Bean, String propertyname, String propertyvalue)
Beanutils.populate (map map, Object Bean)
Commontutils.tobean (map map, class Class)
The action tag associated with JavaBean in the JSP!
- –> finding or creating a bean
- Look for a bean named User1 in the session field, if it does not exist, create the
- Set the Username property value of this javabean named User1 to admin
- Gets the property value named username for the JavaBean named User1
===========================================
El expression
El is a JSP built-in expression language!
- Jsp2.0 starts by not using Java scripts, but instead uses El expressions and dynamic tags instead of Java scripts!
- El replaces <%= ...%>, that is, El can only do the output!
El expression to read four fields
- ${XXX}, the global lookup property named XXX, if it does not exist, outputs an empty string instead of NULL.
- Pag eS CoPe.xxx, {requestscope.xxx}, sessIoNS CoPe.xxx, {applicationscope.xxx}, specify domain Get Properties!
JavaBean Navigation
<%
Address address = new address ();
Address.setcity ("Beijing");
Address.setstreet ("Xisanqi");
Employee EMP = new Employee ();
Emp.setname ("Li Xiaoxi");
Emp.setsalary (123456);
Emp.setaddress (address);
Request.setattribute ("EMP", EMP);
%>
Use El to obtain the EMP of the request domain
${requestscope.emp.address.street}
El can output everything in 11 built-in objects! 11 built-in objects, 10 of which are map! PageContext is not a map, it is the PageContext type, 1 Top 9.
- We have studied four: Pagescope,requestscope,sessionscope,applicationscope.
- PARAM: The corresponding parameter, which is a map, where the key parameter name, value is the parameter value, applies to single-valued parameters.
- Paramvalues: The corresponding parameter, which is a map, where the key parameter name, value is more than one parameter value, applies to multi-valued parameters.
- Header: corresponding to the request header, which is a map, where key represents the header name, value is a single header value, applies to the single-valued request header
- Headervalues: Corresponds to the request header, which is a map, where key represents the header name, value is a multi-head value, applies to the multi-valued request header
- Initparam: Get the parameters inside!
Xxx
Xxx
yyy
YYY
${INITPARAM.XXX}
El function library (provided by JSTL)
- Import Tag Library: <%@ tablib prefix= "FN" uri= "Http://java.sun.com/jsp/jstl/functions"%>
String toUpperCase (String input): Converts a parameter to uppercase
String toLowerCase (String input): Converts arguments to lowercase
int indexOf (string input, String substring): From a large string, output a small string of positions!
Boolean contains (string input, String substring): To see if a string is included in a large string
Boolean containsignorecase (string input, string substring): Ignores case, contains
Boolean StartsWith (string input, String substring): is prefixed with a small string
Boolean EndsWith (string input, string substring): Whether to use small strings as suffixes
String substring (string input, int beginindex, int endIndex): Intercept substring
String Substringafter (string input, string substring): Gets the string that follows the position of the small string in a large string
Substringbefore (string input, string substring): Gets the string in front of the small string in the large string
String EscapeXML (String input): Escapes input "<", ">", "&", "" "," ""
String trim (String input): Remove spaces before and after
String replace (string input, String substringbefore, String substringafter): Replace
String[] Split (string input, string delimiters): Splits a string to get an array of strings
int length (Object obj): You can get the lengths of strings, arrays, various collections!
String join (String array[], string separator): union string Array!
=========================================
Custom Function Libraries
JSP three instructions, nine built-in objects, JSP action tags, el expression and function library