One: servlet
First need a class testservlet inherit HttpServlet, rewrite the method inside, Doget,dopost
Then configure the information in the Config file Web. xml:
<servlet><Servlet-name>Testservlet</Servlet-name><Servlet-class>Com.test.TestServlet</Servlet-class></servlet><servlet-mapping><Servlet-name>Testservlet</Servlet-name></Url-pattern>/testservlet<Url-pattern></servlet-mapping>
Two: Filter
The Testfilter class needs to implement the filter interface to implement all the methods inside, where the Init method is executed when the server is started.
The Dofilter method is to intercept the code that executes after the request is executed, and after execution, the Chain.dofilter method forwards the request to the filter next to it, if not the resource that you requested.
<Filter><Filter-name>Testfilter</Filter-name><Filter-class>Com.test.TestFilter</Filter-class></Filter></filter-mapping><Filter-name>Testfilter</Filter-name><Url-pattern>/testfilter</Url-pattern></filter-mapping>
Three: Listener
There are many kinds of listener in Java: 1: When the client comes in and responds to the request, it is called when the value of the 2:request property changes, and when the property value in the 3:session changes.
4:web is invoked when the service is opened and closed. Wait a minute
You can use this listener if you want to process each request.
<listener><listener-class>TestListener</listener-class></listener>
For more information, you can see 52072655
Use Java's lisener,filter,servlet.