1. Nine built-in objects in JSP:
(1) out object: manages the request information to the client.
(2) request object: obtains the request information of the client.
(3) response object: responsible for sending a response to the client
(4) session Object: stores some information during a session of the same client.
(5) application Object: Information of the entire application environment
(6) exception object: indicates an exception on the page. You can use this object to obtain the page exception information.
(7) page Object: indicates the current JSP page, just like this defined by Java.
(8) pageContext object: indicates the context of the JSP.
(9) config object: indicates the ServletConfig of this JSP
2. response. sendRedirect and What are the differences between the two jump methods?
(1) from the browser address display:
The forward method is used by the server to request resources. The server directly accesses the target address, reads the response content of the target address, and then sends the read content to the browser, therefore, the address of the client browser remains unchanged.
Redirect tells the client to let the browser know which address to request, which is equivalent to re-requesting the client, so the address bar will change.
(2) Data Sharing:
The pages forwarded by forward and the target pages to be forwarded can share the data in the request, while the pages forwarded by redirect and the target pages to be forwarded cannot share the data in the request.
(3) Functional aspects:
Redirect can redirect to other resources of the current application and to resources of other applications on the same site.
The forward method can only forward requests between resources in the same web application. It can be understood as an operation inside the server.
(4) efficiency:
Forward is more efficient, because the jump only happens on the server side.
Redirect is relatively low because it is similar to making another request.
3. Cookie operation: cookie is a common process of transferring data between pages. Cookie is a small text data generated by the server and sent to the client browser. If the client browser is set to enable cookie, the small text data will be saved to a text file in a directory. The next time you log on to the same website, the client browser will automatically read the cookie.
4. You can use either of the following methods to define a JavaBean:
(1) instantiate JavaBean directly in JSP: This is the use of Java code in JSP, not advocate
<%
Student student = new Student ();
// The instantiated student can be used below
%>
(2) Use Tags:
5. Set the JavaBean attribute and obtain the JavaBean attribute.
6. scope of JavaBean:
(1) page: indicates that the function of a JavaBean object is only available on its instantiated page and unavailable on other pages.
(2) request: In addition to being available on the current page, the JavaBean instance can also be used in the forward (3) session: indicates that the JavaBean object can exist in the session, this object can be recognized by all pages of a single user session. (The session is only available for the same client)
(4) application: indicates that the JavaBean object can exist in the application and can be recognized by all pages of all users.
7. Configure servlet in web. xml:
Welcomeservlet
Servlets. WelcomeServlet
Welcomeservlet
/Servlets/WelcomeServlet
The above It is not necessarily a class path, it can be other.
8. When the server is not shut down, only one object is created for several accesses and only one object is created. Will it cause a wait when many users access the server?
Solution: No, because the Servlet uses a multi-threaded mechanism. For each request, the system allocates a thread to run the doGet function, but this also brings security issues. Generally, do not define member variables in the Servlet unless these member variables are shared by all users.
9. Methods for obtaining objects in Servlet:
(1) Get out object: PrintWriter out = response. getWriter ()
(2) Get the request and response objects:
(3) obtain the session object: HttpSession session = request. getSession ()
(4) obtain the application object: ServletContext application = this. getServletContext ()
10. Set and read parameters in Servlet:
(1) set parameters:
Set global parameters: All servlets can access this parameter.
Parameter Name
Parameter Value
Set local parameters: only the Servlet can access this parameter.
Servlet name
Servlet class path
Parameter Name
Parameter Value
(2) obtain parameters:
Obtain global parameters:
ServletContext application = this. getServletContext (); application. getInitParameter ("parameter name ");
Obtain local parameters:
This. getInitParameter ("parameter name ");
11. Servlet redirection:
(1) redirection (corresponding to sendRedirect in JSP built-in object)
Response. sendRedirect ("URL address ");
(2) server redirection (corresponding to the forward tag in JSP ):
ServletContext application = this. getServletContext ();
RequestDispatcher rd = application. getRequestDispatcher ("URL address ");
Rd. forward (request, response );
In general, redirection is used when you do not need to pass parameters or need to jump to another server page. When you need to jump to page B from page, there is a large amount of transient data (that is, the data that is not needed after B page is displayed). To save memory, you can use forward to avoid storing a lot of content in the session.
12. Core tag library declared by JSTL:
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
Core tag Library:
(1) expression operation:
Displays the data content;
Assign values to the attributes of variables or JavaBean;
Delete a variable that exists in the scope.
(2) Process Control:
It is used for simple condition statements;
And And These three tags are usually used together for judgment of complex statements;
The cyclic control label is used to browse the members of a set in sequence. in actual application development, The use frequency is the highest;
A tag is used to browse all members in a string. Its members are separated by delims.
(3) iterative operations:
(4) URL operation.
13. Ajax (Asynchronous JavaScript and XML), when an Asynchronous process call is sent, the caller does not need to get the result immediately, but can continue to do his/her own work until the process call is completed, then, notify the caller through the callback function. In the case of synchronization, the caller must wait for the other party to get the result to continue running.
Ajax contains the following five parts:
(1) asynchronous data acquisition technology: XMLHttpRequest is used (it is the basis of all technologies)
(2) standard representation technology: using XHTML and CSS
(3) Dynamic Display and Interaction Technology: The Document Object Model is used)
(4) data interchange and operation technology: Using XML and XSLT
(5) JavaScript: Integrate the above technologies
14. Five Core steps for implementing the Ajax program:
(1) instantiate the Msxml2.XMLHTTP object in IE:
Var xmlHttp = new ActiveObject ("Msxml2.XMLHTTP ");
Msxml2.XMLHTTP is a built-in object of IE browser. This object provides the ability to asynchronously submit data and obtain results. If it is not an IE browser, the instantiation method is as follows:
<Script type = "text/javascript">
Var xmlHttp = new XMLHttpRequest ();
</Script>
(2) Specify the asynchronous submission target and submission method, and call the xmlHttp open method:
XmlHttp. open ("get", "info. jsp ", true); this method has a single parameter. Parameter 1 indicates the request method, and parameter 2 indicates that the request target is info. jsp. When parameter 3 is true, it indicates an asynchronous request. If it is false, it indicates a non-asynchronous request.
Note: In this case, the Knowledge specifies the asynchronous submission target and submission method, and the actual submission is not performed.
(3) Specify the processing to be performed when the xmlHttp status changes. The processing is generally performed in the form of the corresponding function:
XmlHttp. onreadystatechange = function (){
// Process the code
}
The onreadystatechange event of xmlHttp is used in this code to call the processing code when the xmlHttp status changes. You can also directly write the processing code as a function.
(4) write the processing code:
XmlHttp. onreadystatechange = function (){
If (xmlHttp. readyState = 4)
InfoDiv. innerHTML = xmlHttp. responseText;
}
(5) send a request and call the send function of xmlHttp:
XmlHttp. send ();
15. Ajax has the following advantages:
(1) Reduce the server load and avoid repeated requests when the entire browser window is refreshed.
(2) provide a better user experience.
(3) Further promote the separation of page presentation and data.
Disadvantages:
(1) There are some restrictions on browsers, and incompatible browsers cannot be used.
(2) Ajax does not have a refresh button, and the "back" button on the browser is invalid. Therefore, customers often cannot roll back to previous operations.
16. MVC (Model, View, Controller): a popular design concept during software development. Based on this idea, JSP is divided into three modules. First, JSP is compiled, enter the query code and submit it to the Servlet. The Servlet performs security verification and calls DAO to access the database. The result is displayed in JSP.
From this design idea, we can find that the program is divided into different modules, and the display, business logic, and process control are independent of each other, making the software a great advantage in scalability and maintainability.
M (Model) encapsulates the data structure and transaction logic of the application, and reflects the state of the application. When the data status changes, it can be reflected in the view, javaBean is suitable for this role.
V (View) is an external manifestation of the Model. It is reflected when the Model state changes. JSP is very suitable for this role.
C (Controller) responds to user input, connects the model and view, writes data to the model, and calls the view. Servlet is suitable for this role.
17. Commonly Used components in Structs: JSP, ActionServlet, ActionForm, Action, JavaBean, and configuration files.
(1) user input, JSP form submitted to ActionServlet.
(2) ActionServlet encapsulates the form information in ActionForm and transfers it to Action.
(3) ActionServlet does not directly process the business logic, so it allows Action to call JavaBean (DAO ).
(4) Action returns the JSP page address to be redirected to ActionServlet.
(5) redirect the ActionServlet, and the result is displayed on the JSP.
Note:
(1) ActionServlet first instantiates the LoginForm object, then calls the setAccount function of LoginForm, encapsulates the form data, and then instantiates LoginAction for processing.
(2) LoginForm and LoginAction will not be instantiated after they are instantiated for the first time. This is the same as the Servlet principle. In fact, an object is run in multiple threads.
18. Three major tag libraries of Struts:
(1) struts-html taglib (htm tag Library): Contains to generate dynamic HTML user interface and form tags.
(2) struts-bean taglib (bean tag Library): Contains tags used to access bean and bean properties, and also contains tags for message display.
(3) struts-logic taglib (logical tag Library): Contains tags to manage some logical conditions and perform some operations according to logical conditions.