11月14日filter与在web开发中集成spring培训日记
2006-11-17 14:07
701 查看
首先回顾Web容器调用Servlet的原理与过程,然后讲解了Filter拦截的原理、Filter类与FiterChain类。Filter的注册与运行。编写一个实用案例:用Filter实现对资源的集中访问保护。
再次分析了HttpServlet的doHead与doGet调用原理,讲解了对请求和响应对象进行包装的原理:writer与OutputStream的关系:把麻烦留给自己,把方便留给别人!假HttpServletResponse中的假Writer又是对假OutputStream的包装
让filter1对default Servlet进行拦截,让filter2对.html url进行拦截,当访问a.html文件时,先是哪个filter进行拦截?
下午为大家讲解了spring中的消息资源管理以及如何在web开发中集成spring。
<%@ 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 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><br>
<%
Enumeration e = application.getAttributeNames();
while(e.hasMoreElements())
{
String attributeName = (String)e.nextElement();
out.println(attributeName + "<br>");
}
%>
-------------------------
重点:如果资源文件存储在某个子目录中,应该用“.”来替代“/”。
<beans>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>resource.messages</value>
</property>
</bean>
</beans>
-----------------------------
提示:不配置contextConfigLocation参数也可以,这样,将查找applicationContext.xml文件。其实DispatchServlet也有一个名为contextConfigLocation的参数,如果不设置这个参数,servlet默认使用<servlet-name>-servlet.xml文件来创建其ApplicationContext对象。
<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-->
再次分析了HttpServlet的doHead与doGet调用原理,讲解了对请求和响应对象进行包装的原理:writer与OutputStream的关系:把麻烦留给自己,把方便留给别人!假HttpServletResponse中的假Writer又是对假OutputStream的包装
让filter1对default Servlet进行拦截,让filter2对.html url进行拦截,当访问a.html文件时,先是哪个filter进行拦截?
下午为大家讲解了spring中的消息资源管理以及如何在web开发中集成spring。
<%@ 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 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><br>
<%
Enumeration e = application.getAttributeNames();
while(e.hasMoreElements())
{
String attributeName = (String)e.nextElement();
out.println(attributeName + "<br>");
}
%>
-------------------------
重点:如果资源文件存储在某个子目录中,应该用“.”来替代“/”。
<beans>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename">
<value>resource.messages</value>
</property>
</bean>
</beans>
-----------------------------
提示:不配置contextConfigLocation参数也可以,这样,将查找applicationContext.xml文件。其实DispatchServlet也有一个名为contextConfigLocation的参数,如果不设置这个参数,servlet默认使用<servlet-name>-servlet.xml文件来创建其ApplicationContext对象。
<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-->
相关文章推荐
- 11月14日filter与在web开发中集成spring培训日记
- 11月14日filter与在web开发中集成spring培训日记
- 11月14日filter与在web开发中集成spring培训日记
- 11月14日filter与在web开发中集成spring培训日记
- SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载 【转】
- Eclipse安装CXF插件开发java web service 集成Spring
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- Shiro权限控制框架 ---SpringMVC+Spring+My batis+Mysql+Maven集成开发Web项目
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目以及SSM框架下载
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- SpringMVC+Spring4+Mybatis3集成,开发简单Web项目
- webservice axis 集成spring,开发测试demo
- Spring Boot集成MyBatis开发Web项目
- SpringMVC+Spring4+Mybatis3集成,开发简单Web项目
- SSH开发环境的配置:web.xml、Spring集成hibernate和Spring集成Struts2
- SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载
- 【持久化框架】SpringMVC+Spring4+Mybatis3集成,开发简单Web项目+源码下载