XML一些小知识
所有部署描述符文件的顶层(根)元素为web-app。请注意,XML元素不像HTML,他们是大小写敏感的。因此,web-App和WEB-APP都是不合法的,web-app必须用小写。XML元素不仅是大小写敏感的,而且它们还对出现在其他元素中的次序敏感。举个例子,servlet元素必须出现在所有servlet-mapping元素之前。请注意,所有这些元素都是可选的。因此,可以省略掉某一元素,但不能把它放于不正确的位置。
解决POST乱码问题的过滤器
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
加载spring容器
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:**/applicationContext.xml</param-value>
</context-param>
1,classpath:到指定的class路径中查找文件。
2,classpath*:既包含class路径,也包括jar文件中class路径。
3,**/ :根目录。
4,* : 一般指文件。
5,还可以这样子写:<param-value>classpath*:**/applicationContext-*.xml</param-value>,其中*可以代替很多,比如shiro、quartz、data、jms等。
6,<param-value>classpath*:**/applicationContext.xml</param-value>,如果还有其它要与spring集成的组件,则可以在applicationContext.xml中使用<importresource="applicationContext-shiro.xml"/>
配置前端控制器(SpringMVC)
<servlet>
<servlet-name>manager</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>manager</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
1,一般情况下,在<servlet>中会使用<init-param>这个标签。
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/manager-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
2,这里并没有使用<init-param>,为什么可以不使用呢?(因为可以使用<listener>这个标签)
对<listener>的理解
<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
1,只要在web.xml中配置<listener>,那么放在WEB-INF目录下的配置文件可以在启动web时,自动装配配置信息。
2,一般情况下,都会使用<context-param>这个标签,因为我们有多个组件与spring集成,所以得分类管理。
3,假如只有一个前端控制器的配置文件,命名为manager-servlet.xml并直接放在WEB-INF目录下,在web.xml中配置了<listener>这个标签,则无需在配置<init-param>这个标签。
session的配置
<session-config>
<session-timeout>20</session-timeout>
</session-config>
1,对整个web的session进行设置。单位是分钟。如果是零或者负数则会话将不会超时。
2,setMaxInactiveInterval是设置当前会话的失效时间。单位是秒。如果是零或者负数则会话将不会超时。
<jsp-config>标签
<jsp-config>
<taglib>
<taglib-uri>http://shiro.apache.org/tags</taglib-uri>
<taglib-location>/WEB-INF/shiro.tld</taglib-location>
</taglib>
</jsp-config>