1. What is a servlet? * Server-side Java programs, Servlets need to be handed to the server to run. * Java program related to Javax.servlet.Servlet interface 2, how to use servlet? "Must" * Create a WEB project * Create a class and implement a servlet interface * to the server to run/web-inf/web.xmlRegister Servlets -
Third, The life cycle of the ServletA Java servlet has a life cycle that defines how a servlet is loaded and initialized, how it receives a request and responds to the request, and how it is purged from the service. the life cycle of the Servlet is defined by the javax.servlet.Servlet interface. all java Servlet jav
Servlet Source code parsing: Servlet interface and its important subclasses, servlet Source CodeHere, we will only explain the necessary Servlet, Session, Rrequest, and Response interfaces and their child classes in the Servlet specification. Other content such as websocket,
Servlet interface application (three methods for servlet development) and three methods for servlet
First: implement the Servlet Interface
Public class ServletDemo1 implements Servlet {
@ OverridePublic void init (ServletConfig config) throws ServletException {// TODO Auto-g
Extract the Web. xml file fragment of a project:The access order is 1->2->3->4, where the values of 2 and 3 must be the same.The value in the Url-pattern tag is the URL to be entered in the browser's address bar, which can be named by itself, which accesses a servlet named Servlet-name, and the value of the two Servlet-name tags must be the same because the value
Extract the Web. xml file fragment of a project:The access order is 1->2->3->4, where the values of 2 and 3 must be the same.The value in the Url-pattern tag is the URL to be entered in the browser's address bar, which can be named by itself, which accesses a servlet named Servlet-name, and the value of the two Servlet-name tags must be the same because the value
One, servlet declaration cycleThe 1.Servlet declaration cycle is generally divided into four steps: Load, instantiate, service, destroy.2. Instantiation is performed only once throughout the life cycle.Second, JSP1.Servlet providing data to the JSPRequest.setattribute (,);Example: Request.setattribute ("Key", "Hello");2.Servl
This can be attributed to the following two situations:A, the project under the Web-inf/lib have Servlet-api.jar, and Tomcat brought Servlet-api.jar conflict.Second, the project under the Web-inf/lib contains Javax.servlet package of other jar packages (such as the WebLogic 8.1 weblogic.jar), resulting in a conflict with Tomcat's own servlet-api.jar.
Because T
. For 0, Httpsessin is gone.Clearing all Sessionhs.setmaxinactiveinterval (0) is the safest way to do it.Res.sendredirect ("Welcome");}else{Here's the name of the servlet.Res.sendredirect ("login");///}}catch (Exception e) {E.printstacktrace ();}Read session:try {HttpSession HS = Req.getsession (TRUE);String val = (string) hs.getattribute ("Pass"); Returns the objectif (val!= null){PrintWriter pw = Res.getwriter ();Pw.println (Val);Pw.println (Hs.getid ());}else{Res.sendredirect ("login");}catch
1. Use Digester to parse web.xml files
2, to the resolution of the
3, add the Standardwrapper to the parent node Standardcontext
4. Instantiate the Servlet object at the end of the pipeline chain and execute the Init method and service method
Class org.apache.catalina.startup.contextconfig{protected void Webconfig () {//--------------------------------- --------//1, using Digester to parse web.xml files//-----------------------------------------web
Reprinted from http://blog.csdn.net/iAm333For Servlets, servlet containers, and a servlet container-tomcat These concepts are very clear, reproduced underBefore in open source China saw an article, "Beginner Java Web Development, please stay away from the various frameworks, from the Servlet development", feel very good. I felt ashamed to think of myself before
This article documents the servlet configuration-related usage and the servlet's life-cycle approach in the servlet container.
Tomcat is a servlet container:
1. The servlet container manages the entire life cycle of the servlet and invokes the servlet's life cy
Public class MyClass {
private String variable1;
private static String variable2;
Public MyClass () {
}
public Void Method () {
String Variable3;
}
}
The above is a class that is handy to write, does not have any meaning, just to emphasize some concepts, this is related to this topic:1) Classification of variables in Java:A. Instance variablesB. Local variablesC. Static variablesThis is not a basic Java tutorial
1. HttpServlet
Servlet Interface Sun Company defines two default implementation classes, namely: Genericservlet, HttpServlet. HttpServlet refers to a servlet capable of handling HTTP requests, which adds some and HTTP protocol processing to the original servlet interface, which is more powerful than the servlet interf
Java web Learning notes-Servlet, web Learning notes-servletServlet basics 1. Servlet Overview
The predecessor of JSP is Servlet. Servlet is a small program running on the server. A Servlet is a Java class that can be accessed through the "request-response" programming model
In general, a servlet can accomplish the same function as a CGI.CGI application development is difficult because it requires programmers to have the knowledge to handle parameter passing, which is not a generic skill. CGI is not portable, and CGI applications written for a particular platform can only run in this environment. Each CGI application exists in a process that is activated by a client request and is unloaded after the request is serviced. T
I. Working Principle of Servlet
Servlet runs in the servlet container. The servlet container is responsible for searching, creating, and managing servlet instances throughout the lifecycle. The entire servlet lifecycle can be divi
The servlet life cycle defines how a servlet is loaded, initialized, and how it receives requests, responds to requests, and provides services. Before discussing the servlet life cycle, let's look at these methods:1. Init () methodIn the servlet's life cycle, only the init () method is executed once, which is performed when the server loads the
Servlet Learning (2), servlet Learning
1. Servlet Lifecycle
(1) When the browser accesses the Servlet for the first time, the server will find the full path of the Servlet in the web. xml file based on the path accessed by the browser, and then call the method using reflecti
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.