Servlet and JSP theory knowledge explanation

Source: Internet
Author: User

The servlet is Java server-side programming and is run on the server. differs from the previous Java applet.

Figure A Figure II

As can be seen in figure one: Servers interact with Servlets, browsers do not deal with Servlets

Figure II (server-side internal flow): The user sends a request, requests access to the test1.jsp, and then uses the JSP parser (JSP parser) to convert to a Java file (server-side conversion), the Java file is a servlet, The corresponding Java file is then compiled from the servlet parser with the corresponding class file.

When the JSP is accessed for the first time, the servlet parser needs to parse the corresponding Java file into a class file, if not, to respond directly. (So when we first visited the JSP page, the speed of the visit was somewhat slow)

The action= "/login" in the form refers to a relative path

action= "Login" refers to an absolute path

The JSP will be transformed into a servlet to execute

Jsp

JSP syntax, including three categories:

1. Compiler directives: such as <%@ page.....%>, <%@ taglib....%>,<%@ include....%>

2. Scripting languages such as annotations <!----> <%----%>

3. Action language: <jsp:forword> <jsp:....>

<%! int a = 3; %> the JSP Declaration

<% int b = 3; %> the difference between the two of the script segments of the JSP

A--, b does not change each time the page is refreshed. The intrinsic cause servlet is a singleton pattern, and the JSP-generated servlet uses the final decorated

Summary: The format of the JSP declaration is: <%! A = 3; %> the form of the script segment: <% b = 3; %> When the server converts a JSP into a servlet, the declaration part of the JSP is converted into a member variable of the class, and the scripting language is transformed into a local variable in the method, and the servlet is a singleton pattern, so that the value of the member variable is one, and each user accesses it. While the value of the scripting language is local variables, each user accesses each time, each has a copy, does not affect each other.

Escape character: \ "Double quotation mark \" single quote \ \ Backslash

\ n wrap \ t tab \b Backspace

Nine built-in objects for JSPs

1.request Request object, object represents a request from the client, returns an enumeration object

2.response

3.session Answering Object

4.pageContext Page Context

5.application Application objects

6.out Output Object

7.config Configuration Objects

8.page Page Object

9.exception Exception Object

The purpose of the GetParameter method of the request is to get the parameter values that the client requests over a URL or form. is the client-server interaction, the server to obtain the data sent to the client, you need to use the GetParameter method to obtain.

Session object: Sessions object represents the conversation established between the server and the client. HTTP is a stateless protocol based on the request-response pattern, and Web server has no historical memory for each client request. Use the session when you need to retain customer information in different JSP pages. The session is used to save the client state information. The session object has only one during the conversation.

The methods commonly used in the session are: GetAttribute and setattribute, both of which are available in request and application, and use the same

Simply, the request can only be requested on a single page, because both methods in request are executed on the server side, and the client does not know whether the server side has performed both methods.

However, in application, application is an application-based object whose life cycle is the entire application, that is, when the server starts and the server shuts down. So it uses it to store the content data that will always exist, knowing that the server is shutting down before destroying it.

Because the blog does not allow the packaging of instances, so the instance published on the csdn above, the name is: I am stupid line of the account above

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.