我正在迁移到Spring MVC 4.1 / Tomcat 8,Java 8,我只在一个特定的页面上得到一个完全乱码的页面输出。这种情况没有发生,迁移前,模板和控制器都没有作为迁移的一部分发生变化。在开发环境和测试服务器上都会出现问题。
控制器设置基本如下:
public abstract class AbstractContextSkillController extends BaseProfileController{
public String skill(
SearchProfileEntityVO vo,
ModelMap model,
NativeWebRequest request){
[...]
return "/profile/frm_skills";
}
@Controller
@RequestMapping("/*/??_??/account/user/profile/edit/skill")
public class InContextSkillController extends AbstractContextSkillController {
@RequestMapping(method = RequestMethod.GET)
public String skill(
ModelMap model,
NativeWebRequest request){
if(myCondition) //if false => normal page output, if true => garbled
return "forward:" + URLUtils.getBasePath(request) + "/account/user/profile/edit/skill/med";
SearchProfileEntityVO vo = new SearchProfileEntityVO();
return super.skill(vo, model, request);
}
@Controller
@RequestMapping(value={"/*/??_??/account/user/profile/edit/skill"})
public class CustomInContextSkillController extends AbstractContextSkillController {
@RequestMapping(method = RequestMethod.GET, value="/med")
public String skill(
ModelMap model,
NativeWebRequest request){
SearchProfileEntityVO vo = new SearchProfileEntityVO();
return super.skill(vo, model, request); // => garbled
}
我修改了CustomInContextSkillController以返回与InContextSkillController完全相同的内容,并且我仍然得到乱码输出,当唯一的区别似乎是一个不同的入口点时,这让我感到惊讶。
所有模板都是UTF-8。我删除了Sitemesh以返回纯页面输出并消除了潜在的差异。如果我保持Sitemesh处于活动状态,则只有代表此模板的页面部分会产生乱码输出。如果我使用HELLO WORLD重新启动一个新模板,它也会返回为乱码。
我尝试了各种各样的事情,假设这与转发编码不正确有关。因此,我尝试通过将其添加到onStartup来确保首先使用characterencodingfilter,并尝试将其添加到
@Component
@Order(10)
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
protected void beforeSpringSecurityFilterChain(ServletContext servletContext){
CharacterEncodingFilter characterEncoding = new CharacterEncodingFilter();
FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encoding-filter", characterEncoding);
encodingFilter.setInitParameter("encoding", "UTF-8");
encodingFilter.setInitParameter("forceEncoding", "true");
encodingFilter.addMappingForUrlPatterns(null, false, "/*");
encodingFilter.setAsyncSupported(isAsyncSecuritySupported());
super.beforeSpringSecurityFilterChain(servletContext);
@Order(1)
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
CharacterEncodingFilter characterEncoding = new CharacterEncodingFilter();
characterEncoding.setEncoding("UTF-8");
characterEncoding.setForceEncoding(true);
registerServletFilter(servletContext, characterEncoding);
super.onStartup(servletContext);
我使用Freemarker作为模板语言。有什么建议?我跑出去了
答案 0 :(得分:0)
就我而言,net.sf.ehcache.constructs.web.filter.GzipFilter是罪魁祸首。更改了从web.xml迁移到JavaConfig的行为。