在尝试实现Spring i18n时出现此错误。我在Stackoverflow上检查了其他帖子同样的问题,没有一个解决了我的问题......任何想法都将不胜感激!
完整错误:
type Exception report
message javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'user.title' for locale 'en_US'.
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'user.title' for locale 'en_US'.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'user.title' for locale 'en_US'.
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
org.apache.jsp.index_jsp._jspService(index_jsp.java:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
javax.servlet.jsp.JspTagException: No message found under code 'user.title' for locale 'en_US'.
org.springframework.web.servlet.tags.MessageTag.doEndTag(MessageTag.java:202)
org.apache.jsp.index_jsp._jspx_meth_spring_005fmessage_005f0(index_jsp.java:124)
org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.64 logs.
基于注释的配置:
@Bean
public ResourceBundleMessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("WEB-INF/i18n/messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(new Locale("en"));
resolver.setCookieName("myLocaleCookie");
resolver.setCookieMaxAge(4800);
return resolver;
}
messages_en_US.properties:
user.title= Fill User Form
user.name= Enter Name
user.age= Enter Age
user.submit= Submit
user.success= You have successfully submitted the form
index.jsp(用于简单测试):
<%@ include file="/WEB-INF/jsp/head.jsp"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<body>
<h3> <spring:message code="user.title"/></h3>
</body>
资源包&#34;消息&#34;是在#Con; WebContent / WEB-INF / i18n&#34;和#34; MywebappConfig.java&#34;是用于配置。不要担心控制器和其他东西,因为它们甚至没有在index.jsp中使用。
我认为这个问题必须发生在设置基本名称的配置文件中。有人说使用&#34; / WEB-INF / i18n / messages&#34;而不是&#34; WEB-INF / i18n / messages&#34;但它并没有什么不同。所以.....任何想法??
******** EDIT **************
问一下我的消息捆绑在哪里可能是一个很好的问题?