web.xml文件主要配置如下:

需要加载的配置文件: 类路径下,可以使用通配符配置  类似:classpath:conf/spring/*/*.xml,

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:conf/spring/spring-da.xml,
classpath:conf/spring/spring-res.xml,
</param-value>
</context-param>

上下文加载过滤:

<!-- 上下文加载器 加载 context-param -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

excel模板下载,防止出现压缩包的情况.

<!-- excel模板下载 -->
<mime-mapping>
<extension>xlsx</extension>
<mime-type>application/vnd.openxmlformats</mime-type>
</mime-mapping>

字符过滤器:防止前后台的中文乱码,当然,最好还是保证 前台页面utf-8 后台的编码也是utf-8

<!-- 字符过滤器 -->
<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>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>

SPring mvc的总控制分发配置:

<!-- Spring MVC 总控制器 DispatcherServlet -->
<servlet>
<servlet-name>pmp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:conf/spring/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>pmp</servlet-name>
<url-pattern>*.htm</url-pattern>
<url-pattern>*.action</url-pattern>
</servlet-mapping>

容器校验登录控制,以及请求的拦截:

<!-- security start -->
<security-constraint>
<web-resource-collection>
<web-resource-name>pmp-web-in</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>pmp-web-in</web-resource-name>
<url-pattern>/RES/*</url-pattern>
<url-pattern>/login.jsp</url-pattern>
<url-pattern>/home/error.htm</url-pattern>
</web-resource-collection>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>framework user role</description>
<role-name>*</role-name>
</security-role>
<!-- security end -->

欢迎页面以及错误跳转配置:

<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/home/error.htm?errorCode=500</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/home/error.htm?errorCode=500</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/home/error.htm?errorCode=404</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/home/error.htm?errorCode=403</location>
</error-page>

以上是项目中web.xml的基本的配置信息,可以根据自身的项目信息增加和删除相关的配置项.

下面是spring-servlet.xml文件的相关的配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://cxf.apache.org/core"
xmlns:p="http://cxf.apache.org/policy" xmlns:ss="http://www.springframework.org/schema/security"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/policy http://cxf.apache.org/schemas/policy.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <!-- 启用注解扫描 -->
<context:component-scan base-package="com.lilin.pmp.web" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan> <!-- 启用spring mvc 注解驱动配置 -->
<mvc:annotation-driven /> <!-- 拦截器的配置 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**/*.htm"/>
<ref bean="loginUserInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
<!--===================== view resovler ===================== -->
<bean id="viewResolver" abstract="true">
<property name="attributes">
<props>
<prop key="resRoot">@{resRoot}</prop>
<prop key="uaaResRoot">@{uaaResRoot}</prop>
<prop key="envName">@{envName}</prop>
<prop key="minSuffix">@{minSuffix}</prop>
<prop key="appVersion">@{appVersion}</prop>
<prop key="imgHost">@{imgHost}</prop>
<prop key="imgHostTag">@{imgHostTag}</prop>
<prop key="imgHostNumber">@{imgHostNumber}</prop>
</props>
</property>
</bean>
<bean id="jstlViewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver"
parent="viewResolver">
<property name="order" value="2" />
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="freemarkerResolver"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"
parent="viewResolver">
<!--<property name="cache" value="true"/> -->
<property name="order" value="1" />
<property name="viewNames">
<array>
<value>*.ftl</value>
</array>
</property>
<!-- <property name="suffix" value=".ftl" /> -->
<property name="requestContextAttribute" value="request" />
<property name="exposeSpringMacroHelpers" value="true" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
<property name="allowSessionOverride" value="true" />
<property name="contentType" value="text/html;charset=utf-8" /><!--编码 -->
<property name="viewClass"
value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" />
</bean>
<!-- ===================== view resolver end ====================== --> <!-- 文件上传支持 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize">
<value>104857600</value><!-- 上传文件大小限制为100M,100*1024*1024 -->
</property>
<property name="maxInMemorySize">
<value>4096</value>
</property>
</bean> <bean id="webPropertyConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:conf/main-setting-web.properties</value>
</list>
</property>
<property name="placeholderPrefix" value="@{" />
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
</bean> <bean id="freemarkerConfig"
class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<description>Required for Freemarker to work in web tier</description>
<property name="configuration" ref="freemarkerConfiguration" />
</bean> <bean id="freemarkerConfiguration"
class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<description>Using the Config directly so we can use it outside the
web tier
</description>
<!-- 模板加载路径 -->
<property name="templateLoaderPaths">
<list>
<value>/WEB-INF/freemarker/</value>
<value>/WEB-INF/uaa-freemarker/</value>
<value>classpath:/</value>
<value>/</value>
</list>
</property>
<property name="configLocation">
<value>classpath:conf/freemarker.properties</value>
</property>
<!--全局变量部分 -->
<property name="freemarkerVariables">
<map>
<entry key="xml_escape" value-ref="fmXmlEscape" />
<entry key="html_escape" value-ref="fmHtmlEscape" />
<entry key="base" value="@{base}" />
<entry key="resRoot" value="@{resRoot}" />
<entry key="uaaResRoot" value="@{uaaResRoot}" />
<entry key="appVersion" value="@{appVersion}" />
</map>
</property>
<property name="defaultEncoding" value="utf-8" />
</bean> <bean id="fmXmlEscape" class="freemarker.template.utility.XmlEscape" />
<bean id="fmHtmlEscape" class="freemarker.template.utility.HtmlEscape" /> <!-- ====================== i18n =============================== -->
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:i18n/messages" />
</bean> <bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean
class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
</list>
</property>
</bean>
</list>
</property>
</bean>
</beans>

spring mvc 项目 相关配置文件小结的更多相关文章

  1. Spring MVC——项目的开发流程

    创建项目(IDEA下) 打开IDEA,我们开始创建一个简单的Spring MVC项目,流程如下: 这里要注意一下,我们是基于Maven开发项目,当然是要配置Maven环境的,如果大家之前从来没有配置过 ...

  2. IntelliJ IDEA上创建maven Spring MVC项目

    IntelliJ IDEA上创建Maven Spring MVC项目 各软件版本 利用maven骨架建立一个webapp 建立相应的目录 配置Maven和SpringMVC 配置Maven的pom.x ...

  3. maven Spring MVC项目

    IntelliJ IDEA上创建maven Spring MVC项目 各软件版本 利用maven骨架建立一个webapp 建立相应的目录 配置Maven和SpringMVC 配置Maven的pom.x ...

  4. Java Spring MVC项目搭建(二)——项目配置

    1.站点配置文件web.xml 每一个Spring MVC 项目都必须有一个站点配置文件web.xml,他的主要功能吗....有一位大哥已经整理的很好,我借来了,大家看看: 引用博客地址: http: ...

  5. Spring MVC 项目搭建 -1- 创建项目

    Spring MVC 项目搭建 -1- 创建项目 1.创建 Dynamic Web project (SpringDemo),添加相关jar包 2.创建一个简单的controller类 package ...

  6. Intellij IDEA创建spring MVC项目

    相信各位未来的Java工程师已经接触到了spring MVC这个框架的强大之处,看了很多的教程,都是eclipse的,在intellij IDEA这个强大的工具面前居然不能很顺畅的,今天我就带领大家用 ...

  7. 【Spring】搭建最简单的Spring MVC项目

    每次需要Spring MVC的web项目测试一些东西时,都苦于手头上没有最简单的Spring MVC的web项目,现写一个. > 版本说明 首先要引入一些包,Spring的IOC.MVC包就不用 ...

  8. 使用maven, myeclipse工具构建spring mvc项目

    一.使用myeclipse 创建一个新的 maven项目. (ps:1.在filter过滤的时候输入 webapp 选择"maven-archetype-webapp". 2.在m ...

  9. Java Spring MVC项目搭建(一)——Spring MVC框架集成

    1.Java JDK及Tomcat安装 我这里安装的是JDK 1.8 及 Tomcat 8,安装步骤详见:http://www.cnblogs.com/eczhou/p/6285248.html 2. ...

随机推荐

  1. Computer Vision的尴尬

    原文: Computer Vision是AI的一个非常活跃的领域,每年大会小会不断,发表的文章数以千计(单是CVPR每年就录取300多,各种二流会议每年的文章更可谓不计其数),新模型新算法新应用层出不 ...

  2. Nginx Location指令配置及常用全局变量

    ./configure的含义 在实践安装nginx的时候,不知道./configure是什么意思,这里特地记录一下. 在linux中./代表当前目录,属于相对路径../代表上一级目录,属于相对路径/代 ...

  3. C语言基础 (12) 文件的操作 FILE

    课程回顾 结构体基本操作: 结构体类型的定义 // struct为关键字 Stu为自定义标识符 // struct Stu才是结构体类型 // 结构体成员不能在定义类型时赋值 struct Stu { ...

  4. 【JavaScript框架封装】使用Prototype给Array,String,Function对象的方法扩充

    /* * @Author: 我爱科技论坛* @Time: 20180705 * @Desc: 实现一个类似于JQuery功能的框架* V 1.0: 实现了基础框架.事件框架.CSS框架.属性框架.内容 ...

  5. 封装基于jq弹窗插件

    相信码友们对于$.fn.extexd();$.extend()以及$.fn.custom和$.custom都有一定的了解:我阐述一下我自己对于$.fn.custom和$.custom的理解.有理解错误 ...

  6. Hbash语句

    下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下:   名称 命令表达式 创建表 create '表名称', '列名称1','列名称2','列名 ...

  7. Tensorboard服务激活

    首先确定Tensorflow的具体位置(在Dos环境下,也就是cmd) cd .. cd scripts conda env list activate tensorflow tensorboard ...

  8. 【codeforces 805A】Fake NP

    [题目链接]:http://codeforces.com/contest/805/problem/A [题意] 问你在l..r这个区间内的所有数字: 对于每个数的因子; 出现次数最多的是哪一个; [题 ...

  9. CF876A Trip For Meal

    CF876A Trip For Meal 题意翻译 小熊维尼非常喜欢蜂蜜! 所以他决定去拜访他的朋友. 小熊有三个最好的朋友:兔子,猫头鹰和小毛驴,每个人都住在自己的房子里. 每对房屋之间都有蜿蜒的小 ...

  10. Eclipse设置jdk相关

    2.window->preferences->java->Compiler->设置右侧的Compiler compliance level 3.window->prefe ...