JAVA web servlet class basis

servlet class basic
overview of
running java program on a web server or application server
to create dynamic content on the web effective and powerful solution
from the container to manage the lifecycle of servers to interact with the web
by the sun regulate its function
Servlet API interfaces
throughout Servlet program, the most important is the Servlet interface, this interface define a subclass GenericServlet, but generally do not directly inherited such, choosing instead to subclass inherits GenericServlet according to the protocol used

Writing servlet Step
1. custom class that inherits the HttpServlet
2. The method of rewriting dopost doget and
3. be arranged in web.xml (url formulated mapping relationship and the servlet class, so that the server can create objects reflection)
write time servlet class Do not write the member variables, there is a thread safety issues
Servlet life cycle
1. create an object
2.init method of execution (initialize the servlet)
3.doget / doPost execution, service
4.destory method of execution, the destruction of the servlet
5.jvm GC recovery servlet objects, unloading servlet
the web.xml configuration
basic configuration
1.url-pattern label must begin with /
2.servlet table servlet-name and servlet-mapping tag servlet-name must be consistent,
otherwise it can not find servlet class
<url-pattern> matching rule
1. completely matching
2. directories matching
3. extension matches
the vessel lookup rules
1. the vessel will first find an exact match, if you can not find the directory to find matches, and then if you still can not find find extensions name matching
2. If a request can match multiple directory matches, the container will choose the longest match directory
Servlet3.0 new features
1.annotation support annotations
2. The modular programming
3.servlet Asynchronous Processing
4. Asynchronous The Listener
5. The file upload API simplified
ServletContext application context
1. belongs to the web application
a local input 2 can access the web application resources stream
virtual path 3. The resource conversion physical path. (The getRealPath ()
4. event logging
5. bound objects are shared across a web application
Servlet sharing information
to the parameter values in real time all servlet provided a change in
the shared objects in a web application,

Guess you like

Origin www.cnblogs.com/wind-copy1234/p/11768931.html