JSP learning notes

xiaoxiao2021-03-06  88

Monday, 2004-9-27 Monday

JSP introduction

1. Overview: 1) Based on the text can return dynamic content to the client; 2) HTTP is the default protocol for request and response; 3) A page can be mixed with HTML code, Java code, and JSP tidaration; Component;

2. Good Answers in JSP: 1) Use support component model and software reuse by components; 2) Source file changes automatic compilation; In terms; 5) platform-independent; 6) Performance and scalable; 7) Reliability; as part of J2EE (servlet, JSP, and EJB are three components of J2EE).

Create, configure, and execute JSP

1. JSP Answer: 1) Development Environment A. Browser: IE / Netscape B. Development Tools: Notepad, Sunone Studio, JBuilder, WSAD 2) Configuration and Execute Environment A. Tomcat B. Weblogic C. WebSphere D. Sunone Application Server

2. First JSP page answer: 1) Script Padt: Corresponds to the service method <% ...%> or 2) instructions (Directives "in the service method in the service method in the servlet ) A. Page <% @ Page Import = "java.util. *"%> Or B. Include <% @ include file = "footer.jsp "%> Or 3) Declaration (Declarations) <%! String str =" this is a string! ";%> Or str =" This is a

String! " 4) Expression (Expressions) <% = Str%> or Str

2004-9-28 Tuesday

1. In the JSP page, you can use the following scripting elements to insert Java code Answer: 1) declarations: <%!%> Or 2) Script Practice (Scriptlet): < % ...%> or 3) Expression (Expressions): <% =%> or 4) Instruction (Directives): <% @%> Or

2. Declarations: 1) Allow definitions to be inserted into the main body of the servlet class (by the service call, with the service () method level) method or domain; 2) Syntax: <%! Java code%> Or 3) Example: a. Variable Definition: <%! INT i = 0;%> B. Method Definition: <%! Public String F (INT I) {IF (i <3) Return ("..."); ...}%> 4) Declaration rules: a. Variables and methods declared in JSP correspond to instance methods and instance variables in the servlet. These will be shared by all users of the page; b. Before using variables or methods, you must define (not said that the position of the declared variable is in front of the use variable, but means the variable is not

Can't use); c. The scope of the declared variable or method is the current page or contains the page; D. Statement is separated by a semicolon.

3. Scriptlet Answer: 1) Java code snippet, can perform functionality than mark language 2) Syntax: <% ...%> or 3) Script small program rules: a. The scripting language you use determines the rules of the script applet; b. Statements are separated by semicolons; c. You can use the default object, Import into classes, declass declaration methods and objects, and usebean Objects declared in tag.

4. Expression Answer: 1) Used to insert the value directly into the output 2) Syntax: <% =%> or 3) Expression rules: a. You The scripting language used determines the rules of the script applet; b. The order in which the execution is from left to right; c. Sequel not for expression.

5. Directive Answer: 1) Page: Define the global attribute syntax of the page: <% @ Page ...%> or 2) Include: Insert a static page content syntax : <% @ Include file = "header.jsp"%> or

6. Operations Answer: 1) Forward Action: Point the request to a specific page (similar to the requestDispatcher in the servlet); syntax: 2) Include operation: Insert on the page Dynamic content syntax: 3) Plugin action: Embed an object syntax in the output page: ... 7. Note: There are two types of annotations in JSP: 1) Server Note: Will not send back Client <% - this is a comment -%> 2) Client note: Send back to client 8. JSP processing: A: JSP source file processing is divided into two phases: 1 ) JSP page conversion phase: The page is compiled into a Java class, all HTML tags and JSP tags are converted to create a servlet. At this time

, Scripts and expressions have not been executed; 2) Request processing Phase: A client requests a client request to the JSP page. A request object creation, resolution, and submit to compile

The corresponding servlet corresponding to JSP. When this servlet is requests, it performs the processing script applet and expressions previously defined in JSP.

9. Use the shortcomings and guidelines for script code: 1) Disadvantages: a. Excessive scripting code uses JSP page confusion and difficult to maintain; b. Scripting code reduces JSP two main advantages: software reuse and code separation 2) Guide Policy: Use only when component functions are in powerless or need limited scripts.

Wednesday, 2004-9-29 Wednesday

1. JavaBeans A: 1) JavaBeans is a lightweight, platform-independent, a component model written with Java to create reusable components; 2) Beans can be generated to create a robust, cross-platform application and applet .

2. JSP and components Answer: 1) When needed, JSP can access JavaBean and EJB; 2) JSP uses the Action tag to use, modify, and create server-side objects (such as beans);

3. JavaBean Answer: 1) Bean class must have a constructor without parameters; 2) The bean class should have no public instance variable (domain); 3) consistent values ​​should be obtained by GET and SET methods .

4. Basic use of bean: 1) Call bean syntax: can usually be equivalent to a small script: runnable thread1 = new myclass The above code means that only the class objects specified by the class only when there is no object having the same ID and Scope, and bind it to the variable 2 of the ID specified by the ID 2) Access bean's attribute syntax: or <% = Book1.gettitle ()%> 3) Set the bean properties a. Simple case syntax: or <% book1.settitle (" Core Servlets and JavaServer Page);%> b. Using JSP Expression as Value Parameter Syntax: c. Establish an association syntax between individual properties and input parameters: / / Use param to specify the input parameters, this parameter value is automatically used as this attribute value, and automates

Simple type conversion d. Create all attributes and input parameters: Need notice: i: When the input parameter is lost, no operation is performed, The system does not provide null as an attribute value; II: Unable to complete the type conversion of the attribute of the value of Double; IV: When using the automatic type conversion, you need to consider the error handling page; V: Attribute name and input parameters must be fully matched.

5. Share Bean Answer: 1) Scope Scope: A. Variables will also be located in the servletContext object; c. Session: Indicates that the bean object is binding to a local variable, and will be located in the HTTPSession object located in the current request; D. Request: Indicates the bean object, in addition to being bound to local variables, It will also be in the servletRequest object; 2) Ways to call beans: statement (only when creating beans instead of using existing beans) 2004-9-30 Thursday sunny

Abnormal processing

1. Runtime Answer: 1) An error in a program running; 2) Can be used in an inherent exception object reference; 3) You can create or generate a JSP page to display exception information to the user using an exception reference.

2. Create an exception tracking scheme: 1) In each JSP page, contain the exception page name to be created; <% @ page import = "Numberguess.NumberguessBean" ErrorPage = "error.jsp"%> 2) Create an exception Page; <% @ page isrrorpage = "true"%>

3. Answer: 1) <% = exception.toString ()%> Print anomalies; 2) <% exception.printStackTrace ();%> Print all errors in the current error stream; 3) <% = exception.getMessage ()%> Detailed description information of printing errors

Advanced theme

1. JSP in Summerside recognize the intrinsic objects A: Name Type Comment and scope of the request javax.servlet.http.HttpServletRequest request response javax.servlet.http.HttpServletResponse response pageContext javax.servlet.jsp.PageContext page session javax.servlet.http. HttpSession session application javax.servlet.ServletContext ServletContext out javax.servlet.jsp.JspWriter output stream config javax.servlet.ServletConfig ServletConfig page javax.lang.Object page Exception java.lang.Throwable page

2. Request A: Request) A: Method: 1) getCookies: Get a cookie array; 2) getMethod: Return to the request formation (Get / post); 3) getParameterNames: return to Form Object name enumeration; 4) getParameter: Returns the object value of the specified name; 5) getParameterValues: Returns the object value array of the specified name; 6) SetAttribute: Setting the property; 7) GetAttribute: Return to the property value; getAttributeNames: Return the property name Enumeration 3. The default object OUT Answer: An instance of JSpWriter, used to send response to client methods: 1) Print / println (string) 2) Print (int) / println (int) 3) Flush ( )

4. EXCEPTION Answer by default: 1) Exception instance for exceeding an abnormality object;

5. Default Objects Answer: 1) An instance of httpsession for keeping state in a session 2) method: getAttribute () setttribute () Removeattribute () getAttributeNames ()

6. Application Answer for Default Objects: 1) ServletContext An instance for keeping Application Status 2) Method: GetAttribute () setttribute () getinitParameter () getServletInfo () 3) Application's scope is much larger than session, one session Contact with a client, and Application has maintained for all guests

Noodle status

转载请注明原文地址:https://www.9cbs.com/read-95644.html

New Post(0)