Java Servlet Learning Notes (ii)

Source: Internet
Author: User

The Java filter is loaded when the service container is started, and its load order is consistent with the order of registration in Web. Xml.


SERVLET3.0 below, you need to register in Web. XML with the following definitions.

<fileter>    <filter-name></filter-name>    <filter-class></filter-class>    <init-param>        <param-name></param-name>        <param-value></param-value>    </init-param></filter><filter-mapping>    <filter-name></filter-name>    < Servlet-name></servlet-name>    <url-pattern></url-pattern></filter-mapping>

More than Servlet 3.0, you can register the filter directly in the class file as a comment.

@WebFilter (filtername= "", urlpatterns={}, initparams={@WebInitParam (name= "", Value= "")})

When a user sends a request to the server, Tomcat first creates a request object of type HttpServletRequest and a response object of type HttpServletResponse. Then determine the URL address of the room request or whether the corresponding servlet has a filter defined, and if so, call its Dofilter method. In this method, there is a very important statement, China.dofilter (request, response), if you want to continue to execute the room-side request servlet or URL must have this line of code, otherwise, the filter is not considered to give release, the customer request will be filtered out.


The parameters specified when filtering is defined in Web. XML can be read by the Init () method in the Filter class.

public void init (filterconfig config) throw servletexception {    String encoding = cofig.getinitparamter ("encoding"); ..}


Java Servlet Learning Notes (ii)

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.