您好,登录后才能下订单哦!
一:web.xml文件配置
<servlet> </servlet-mapping> |
添加编码过滤器
<filter> <filter-name>encoding</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>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
logback集成到SpringMVC项目中
<context-param> <param-name>logbackConfigLocation</param-name> <param-value>classpath:logback.xml</param-value> </context-param> <listener> <listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class> </listener> |
二:spring-mvc.xml文件配置
<context:component-scan base-package="com.ultrapower.bjd.web"> </context:component-scan> |
<mvc:default-servlet-handler /> |
配置freeMarker的模板配置信息
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"> <property name="templateLoaderPaths"> <array> <value>/WEB-INF/freemarker/</value> <value>/WEB-INF/freemarker/mgr/</value> <value>/WEB-INF/freemarker/anls/</value> </array> </property> <property name="freemarkerSettings"> <props> <prop key="incompatible_improvements">2.3.22</prop> <prop key="template_exception_handler">rethrow</prop> <prop key="default_encoding">UTF-8</prop> <prop key="locale">zh_CN</prop> <prop key="date_format">yyyy-MM-dd</prop> <prop key="time_format">HH:mm:ss</prop> <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop> <prop key="number_format">0.################</prop> </props> </property> </bean> |
配置Freemarker视图解析器
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"> <property name="prefix" value="" /> <property name="suffix" value=".html" /> <property name="contentType" value="text/html;charset=UTF-8" /> <property name="order" value="0"></property> <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /> </bean> |
配置其他视图解析器(处理JSP类型的试图解析器 处理的视图为:InternalResourceView或者JstlView)
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="" /> <property name="suffix" value=".jsp" /> <property name="contentType" value="text/html;charset=UTF-8" /> <property name="order" value="1"></property> </bean> |
配置全局的拦截器
<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="com.ultrapower.bjd.web.interceptor.UserVilitorInterceptor" /> </mvc:interceptor> </mvc:interceptors> |
其它(使用FastJson)
<mvc:annotation-driven > class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"> |
三:使用
@Controller return new ModelAndView(new FastJsonJsonView(),modelMap) ; @RequestMapping(value = { "**/{page}.html", "**/{page}.xhtml"}) @ResponseBody |
public class ExcelXlsView extends AbstractXlsView{
@Override HttpServletRequest request, response.setContentType("application/vnd.ms-excel;charset=utf-8"); + URLEncoder.encode(fileName, "UTF-8") + ".xls"); } } 参考: |
部分Maven配置
<properties> </properties> </dependencies> |
<build> <finalName>guest</finalName> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> <include>**/*.conf</include> <include>**/*.drl</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*</include> </includes> <filtering>false</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5</version> <configuration> <source>1.7</source> <target>1.7</target> <encoding>UTF-8</encoding> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <version>2.2</version> <configuration> <server>tomcat6</server> <path>/guest</path> <charset>UTF-8</charset> <uriEncoding>UTF-8</uriEncoding> </configuration> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <server>tomcat7</server> <path>/guest</path> <charset>UTF-8</charset> <uriEncoding>UTF-8</uriEncoding> </configuration> </plugin> </plugins> </pluginManagement> </build> |
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。