"Web Foundation" Jsp/servlet Simple Review

Source: Internet
Author: User

HTTP status code:

2XX: Request succeeded

3XX: redirect

4XX: An error occurred in the client. 403-Forbidden-access is not required even with authorization. 404 the server cannot find the specified resource and the document does not exist.

4XX: Server error occurred. 500 Server Internal Error-the server could not complete the request because of an unexpected situation.


JSP section:

JSP built-in objects:

1 page context--javax.servlet.jsp.pagecontext2.request--javax.servlet.http.httpservletrequest

Interface definition: public interface HttpServletRequest extends Serlvetrequest

Important method: Public Httpsesson Getsesssion

3.reponse--javax.servlet.http.httpservletreponse

Interface definition: public interface HttpServletResponse extends Servletresponse

Important method: public void Addcookie (Cookie cookie)

public void SetHeader (string name, string value) sets the header information for the response example: two seconds Jump: Reponse.setheader ("Refresh", "2; Hello.htm "); client Jump

IMPORTANT: 1. Operating cookies:

Definition: Javax.servlet.http.Cookie

Method: Cookie (string name, String value), GetName, GetValue (), setmaxage (int expiry) in seconds

2. About the two types of jumps:

Server-side Jump (browser address does not change): <jsp:forward>, that is, the client does not have a request

Client Jump (Browser address change): Reponse.sendredirect ()

public void Seedirect (String location) throws IOException

4.session--javax.servlet.http.httpsession

After the user connects to the server, the server automatically assigns a Sesison to the SessionID, and the server relies on different sessionid to differentiate between different users.

Session invalidation after server restart, workaround: Save the session in a serialized way continue to use, can be configured in Tomcat Servier.xml, save Sessio to file.

5.application--javax.servlet.servletcontext6.config--javax.servlet.servletconfig7.out-- Javax.servlet.jsp.jspwriter8.page--java.lang.object9.exception--java.lang.throwable


4 Range of properties:

Page: effective, jump invalid

Request: Once the requests are valid, the server jumps are still valid and the client is invalid.

Session: A conversation scope is valid, regardless of any jump can be used, that is, client-side jump valid, but the new browser can not be used.

Application: Saved on the entire server and available to all users.


Servlet section:

JSP can do dynamic web development, but from the developed code found that there is a large number of code on a page, resulting in writing maintenance and extensibility difficulties.

A Servlet (server-side applet) is a server-side program written in the Java language. is the implementation of the CGI program in Java, but unlike the traditional CGI multi-process processing operation, the servlet uses multithreading, which makes the servlet program run more efficiently than the traditional CGI, and the servlet also preserves Java's portability difficulties.


Servlet program Processing steps:

1. The client sends an HTTP request

2. The Web server receives the request and sends it to the servlet. If the servlet has not yet been loaded, the Web server will load it into the Java virtual machine and execute it.

3. The servlet program accepts the HTTP request and executes the processing.

4. The servlet returns an answer to the Web server after the processed structure.

5. The Web server sends an answer received from the servlet to the client.

Servlet Program Implementation:<<intferace>>servlet<--genericservlet<---httpservlet<---custom servlet


Web. XML Configuration servlet:

<servlet>

<servlet-name>hello</servlet-name>

<servlet-class>servlet class </servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>hello</servlet-name>

<url-pattern>/helloServlet</url-pattern>< map Path to!--page--

</servlet-mapping>


Servlet life cycle:

The life cycle includes:

Loader, initialize, service, destroy, uninstall. The corresponding HttpServlet methods are: Init () \init (servletconfig config), service, Destory.


Servlet Jump:

Client Jump: Use Httpservletreponse's SENDREDIRCT (), but this jump can only pass properties of session and application scope.

Server jump: Rely on the RequestDispatcher interface, provide the method: Forward (servletrequest req,servletresponse response), include (...);


Filter:

JSP can complete the functionality of the servlet can be completed, but the servlet has a function that JSP does not have, from the use of the servlet can be divided into:

Simple servlet, filter servlet, listener servlet. 3 kinds.

Specific interfaces and methods slightly;

Application: Coded filtering, user login verification.


Listener:

Responsible for monitoring the various operations of the Web.

1, the monitoring of application, is actually the ServletContext (servlet context) monitoring, The main use of Servletcontextlistener and Servletcontextattributelistener two interfaces.

The first represents the context state listener, and the second represents the context property listener.

2, the session monitoring, mainly using Httpsessionlistener, Httpsessionattributelistener, Httpsessionbindinglistener interface (not configured to use directly).

3, the request listens, uses the Servletrequestlistener and Servletrequestattributelistener two interfaces.

Applications: such as online personnel statistics ...




"Web Foundation" Jsp/servlet Simple Review

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.