0
编码问题。 Spring MVC控制器从ajax char'?'收到而不是“A”等等......所有网页上的编码是UTF-8,在JavaScript文件显示正确的字符警惕,设立Ajax和添加过滤器不工作spring mvc ajax编码
*javascript*
$.ajax({
url : urlID,
contentType: "text/html; charset=utf-8",
data : parameters,
success : function(data, textStatus) {
$(contentID).empty().html(data);
},
error : function(jqXHR, textStatus, errorThrown) {
$("#errorMessage").empty().html(
"<h3>Exception: " + errorThrown + "</h3>");
}
});
控制器
@RequestMapping(value = "/marketing-changepage", method = RequestMethod.GET)
public String marketingChangepage(HttpServletResponse response, @RequestParam String startDate,
@RequestParam String endDate, @RequestParam String device,
@RequestParam String source, Model model, Principal principal) {
AjaxRequestParams ajaxRequestParams = new AjaxRequestParams();
ajaxRequestParams.setDateRange(new DateRange(startDate, endDate));
ajaxRequestParams.setSource(source);
ajaxRequestParams.setDevice(device.toLowerCase());
ajaxRequestParams.setClientInfo(userService
.fetchClientInfoByUserName(principal.getName()));
preparePage(ajaxRequestParams, model, principal);
return "marketing/content_marketing";
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/root-context.xml
</param-value>
</context-param>
<listener>
<listener-class>ch.qos.logback.ext.spring.web.LogbackConfigListener</listener-class>
</listener>
<context-param>
<param-name>logbackConfigLocation</param-name>
<param-value>/WEB-INF/logback.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>charsetFilter</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>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/WEB-INF/views/generalerror.jsp</location>
</error-page>
</web-app>
tomcat?或玻璃鱼? – 2014-10-06 09:05:58
tomcat 7服务器 – eriksson 2014-10-06 09:10:17