I. Several Action elements of JSP: Three (custom tags embedded in JSP for the server) 1. jsp: include: Implement Dynamic include attribute: page. the URL of the target component. Starting with "/", it indicates the absolute path. 2. jsp: forward: the URL address of the target component to which page is redirected. Starting with "/", it indicates the absolute path. 3. jsp: Param function: add request parameter property: name parameter name value parameter value <JSP: Forward page = "/2.jsp">
<JSP: Param value = "MJC" name = "name"/> <JSP: Param value = "123" name = "password"/> </jsp: forward> the above Code Description turns to 2. in JSP, request parameter 2 for passing a name and nine implicit objects in JSP (in java scripts in JSP, you do not need to define objects that can be directly used. --- Variables in the servlet service method corresponding to JSP) built-in object (variable name) corresponding type request
Javax. servlet. http. httpservletrequestresponse
Javax. servlet. http. httpservletresponsesession
Javax. servlet. http. httpsession (prerequisite page command session = "true") Application
Javax. servlet. servletcontextconfig
Javax. servlet. servletconfigpage
Thisexception
Java. Lang. throwable (iserrorpage = "true" of the prerequisite page command) --------------------------------------------------------- out
Javax. servlet. jsp. jspwriterpagecontext
Javax. servlet. JSP. pagecontext; 1. built-in out object (javax. servlet. JSP. jspwriter) Detailed description of the character output stream, equivalent to printwriter (servletresponse. getwriter () result data displayed by the user: It is obtained from the cache of the servletresponse stream. 2. built-in pagecontext object (javax. servlet. JSP. pagecontext) three major functions: A. Get 8 hidden objects in other JSP: Get jsp9 implicit objects in common classes. B. Provide a simple request for inclusion and forwarding. getrequestdispatcher ("url "). forward (request, response); Request. getrequestdispatcher ("url "). include (request, response); pagecontext. forward ("url"): Forward pagecontext. include ("url"): contains C, is a domain object, and can operate data C.1 In other domain objects itself is a domain object. Imagine there is a map <string, object> void setattribute (string STR, object OBJ) object getattribute (string Str) void removeattribute (string Str) Note: The object stored in the pagecontext domain is only valid on the current page. C.2 operate data in other domain objects (other domain objects servletcontext httpsession servletrequest) void setattribute (string STR, object OBJ, int scope) object getattribute (string STR, int scope) void removeattribute (string STR, int scope) Note: The scope parameter is an integer and it is a constant defined in pagecontext (pagecontext. application_scope pagecontext. session_scope pagecontext. request_scope pagecontext. page_scope) C.3 very important method: Object findattribute (string S): Search for S in order of page, request, session, and application scope Data, locate the location. 3. Four domain (range) objects (Role: encapsulate data and transmit data) type of the domain object the reference name in JSP indicates the range pagecontext pageservletrequest request requesthttpsession session sessionservletcontext application 4. The concept of Javabean is a common Java class (pojo, do -- data object, Vo -- value object, domain (domain) objects) are generally placed in the domain package. Features: 1. The class must have a default constructor. 2. Fields in the class are private. 3. Provide public getter or setter methods (attributes) 4. Classes are generally declared as public. 5. java. Io. serializable interfaces are generally required. During Java EE development, the main function of Javabean is to encapsulate data. Note: comply with Java Naming rules. 5. Use Javabean in JSP: three action elements. 1. Use JSP: usebean to find the object with the specified name from the specified domain range. If yes, the application of the Object is returned. If no, create a new object and store it in the domain range. attribute: ID: required. Indicates the reference name of the object to be searched. Class: object type. Scope: the specified range. The default value is page. Optional value: Page | request | session | application2, JSP: setproperty: set the value for the specified property. Property: Attributes of JavaBean (corresponding to the setter method of JavaBean: for example, setname, write name here). wildcard * Name: specify the JavaBean attribute for which the tag is set (JSP: usebean needs to be called before using the tag) value: Set the attribute value. Automatic type conversion (basic type only) (Java expression assignment supported) Param: name of the Request Parameter 3. jsp: getproperty function: Get the Value Attribute of the specified property: Name: specify the JavaBean attribute to be obtained (JSP: usebean needs to be called first when using this tag) Property: JavaBean attribute (corresponding to the getter method of JavaBean: for example, getname, write name here) Note: if the value of an attribute is null, null (this is not good) is displayed when the tag is output. 6. Sun's javaweb Design Models 1. Model 1: JSP + JavaBean development 2. Model 2: servlet + JSP + JavaBean development. MVC + three-tier architecture model: JavaBean view: jspcontroller: servlet 7. El expression 1. Why Learning El expressions? The purpose is to replace the Java expression (<% = expression %>) in JSP 2. Basic Syntax: $ {El expression}. The function is to output the operation result of the expression to the page. 3. Detailed functions: A. Get the attributes of an object. The expression a.1el can only obtain the attributes of objects in the domain. Operator:. OPERATOR: Get object attributes (call object's getter method) [] OPERATOR: Get object attributes, which must be enclosed by quotation marks .. [] Can be used for operators, [] can be used for operators, and. cannot be used for operators. The obtained attribute or key value does not comply with Java Naming rules. Note: If the object obtained by El does not exist, no NULL pointer exception is reported and nothing is output. If the retrieved property does not exist, an exception is reported. B. Perform simple mathematical and logical operations on the B .1empty operator. The result is true or false. Determines whether an object or set is null or a "" string. If yes, true is returned. Note: If the set type is determined, the empty operator returns true even if the set object is not empty and no element exists. B .1 ternary OPERATOR: $ {logical expression? True indicates execution. If false, execution is performed}
Note: The El expression does not support string join operations. C. obtain common Java Web development objects (El has 11 implicit objects). Note: Be sure to distinguish these 11 El built-in objects from the JSP built-in objects, only one object represents the object itself, and the other 10 objects represent a map structure. Pagecontext: Type javax. servlet. jsp. pagecontext. -------------------------------------------------------- Pagination: the map field maintained in the pagecontext object. Requestscope: sessionscope: applicationscope: Param: indicates the Map <string, string> that encapsulates the request parameters. Key is the request parameter name. The value of the request parameter, which is a string. Paramvalues: Map <string, string []> that encapsulates request parameters. Key is the request parameter name. Array of value request parameter values. Header: indicates the Map <string, string> that encapsulates the request message header. Key is the request header name. Value indicates the request header value, which is a string. Headervalues: indicates the Map <string, string []> that encapsulates the request message header. Key is the request header name. The value request header value array. COOKIE: indicates the Map <string, Cookie> that encapsulates the cookie. The key is the name of the cookie, and the value is the cookie object itself. Initparam: indicates the initialization parameter Map <string, string>. Key is the parameter name and value is the parameter value. Parameter: Web. XML <context-param> <param-Name> encoding </param-Name> <param-value> UTF-8 </param-value> </context-param> D, call common static Methods of Java classes (custom El functions) 8. jstl core Tag: C: If C: foreach objective: JSP cannot contain a line of java scripts and expressions. Simple case: MVC + three-tier architecture. database: memory database; JSP + Servlet implementation. User Registration and login case: MVC + three-tier architecture. Database: XML; JSP + Servlet implementation.
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.