In November 14, filter was integrated with spring training diary in Web development.

Source: Internet
Author: User

First, let's review the principles and processes of Web containers calling servlet, and then explain the principles of filter interception, filter class and fiterchain class. Register and run the filter. Write a practical case: Use filter to implement centralized resource access protection.

I analyzed the dohead and doget calling principles of httpservlet again, and explained the Packaging Principles of request and response objects: the relationship between writer and outputstream: Leave the trouble to myself and leave convenience to others! The false writer in the false httpservletresponse is the packaging of the false outputstream.

Let filter1 intercept the default servletobject, And let filter2intercept the .html urlobject. Which filter is used to intercept the.html file?

This afternoon, I will explain how to manage Message Resources in spring and how to integrate Spring into web development.
<% @ Page contenttype = "text/html; charset = gb2312" %>
<% @ Taglib prefix = "itcast" tagdir = "/WEB-INF/tags/test" %>
<% @ Page import = "org. springframework. Context. Support. classpathxmlapplicationcontext" %>
<% @ Page import = "org. springframework. Context. applicationcontext" %>
<% @ Page import = "org. springframework. Web. Context. webapplicationcontext" %>
<% @ Page import = "org. springframework. Web. Context. Support. webapplicationcontextutils" %>
<% @ Page import = "Java. util. enumeration" %>

<Itcast: defineconstants/>

$ {Constants. Green}

<%
Applicationcontext =
// Webapplicationcontextutils. getwebapplicationcontext (application );
(Applicationcontext) application. getattribute (
Webapplicationcontext. root_web_application_context_attribute );
// = New classpathxmlapplicationcontext ("/resource/applicationcontext. xml ");
%>
<% = Applicationcontext. getmessage ("Hello. Title", null, request. getlocale () %>

<% = Webapplicationcontext. root_web_application_context_attribute %>

<Br>

<%
Enumeration E = application. getattributenames ();
While (E. hasmoreelements ())
{
String attributename = (string) E. nextelement ();
Out. println (attributename + "<br> ");
}
%>

-------------------------
Note: If the resource file is stored in a subdirectory, replace "." with "/".

<Beans>
<Bean id = "messagesource" class = "org. springframework. Context. Support. resourcebundlemessagesource">
<Property name = "basename">
<Value> resource. Messages </value>
</Property>
</Bean>

</Beans>

-----------------------------
Tip: do not configure the contextconfiglocation parameter. In this way, the applicationcontext. xml file will be searched. In fact, dispatchservlet also has a parameter named contextconfiglocation. If this parameter is not set, Servlet uses the <servlet-Name>-servlet. xml file by default to create its applicationcontext object.
<Listener>
<Listener-class> org. springframework. Web. Context. contextloaderlistener </listener-class>
</Listener>
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value>/WEB-INF/applicationcontext1.xml </param-value>
</Context-param>

---------------------------------
<Listener>
<Listener-class> org. springframework. Web. Context. contextloaderlistener </listener-class>
</Listener>
<! -- Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value>/WEB-INF/applicationcontext. xml </param-value>
</Context-Param -->

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.