javax.servlet.jsp.JspTagException:在代码' errors.contact.sysadmin.msg'下找不到任何消息。对于语言环境' en_US'。]

时间:2015-03-16 16:20:38

标签: spring jsp spring-mvc

我已经配置了这样的消息资源:

tradelc-servlet.xml中

<bean id="messageSource"
          class="org.springframework.context.support.ResourceBundleMessageSource">
          <property name="basename" value="WEB-INF/classes/resources/application" />
   </bean>

我也试过

<bean id="messageSource"
              class="org.springframework.context.support.ResourceBundleMessageSource">
              <property name="basename" value="resources.resources.application" />
       </bean>

我最初根本没有application_en.properties.xml。但是我跟着this input并在tomcat classes文件夹,src和目标文件夹中创建了一个。

但我仍然得到同样的错误。

org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [tradelc] in context with path [/tradelc] threw exception [javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'errors.contact.sysadmin.msg' for locale 'en_US'.] with root cause
javax.servlet.jsp.JspTagException: No message found under code 'errors.contact.sysadmin.msg' for locale 'en_US'.
       at org.springframework.web.servlet.tags.MessageTag.doEndTag(MessageTag.java:202)
       at org.apache.jsp.WEB_002dINF.jsp.errors.general_jsp._jspx_meth_spring_005fmessage_005f0(general_jsp.java:141)
       at org.apache.jsp.WEB_002dINF.jsp.errors.general_jsp._jspService(general_jsp.java:89)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
       at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
       at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
       at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
       at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:746)
       at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:716)
       at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:868)
       at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
       at org.apache.jsp.WEB_002dINF.jsp.menu_jsp._jspService(menu_jsp.java:296)
       at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
       at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
       at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
       at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
       at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:487)
       at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:412)
       at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:339)
       at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209)
       at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:266)
       at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
       at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
       at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
       at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
       at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)
       at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:822)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
       at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:807)
       at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at com.bankofny.inx.omx.lc.web.action.CharsetFilter.doFilter(CharsetFilter.java:45)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
       at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
       at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1008)
       at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
       at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
       at java.lang.Thread.run(Unknown Source)

请帮助

4 个答案:

答案 0 :(得分:1)

您必须提供基本名称约定(http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/support/ResourceBundleMessageSource.html#setBasename-java.lang.String-http://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.html),您将看到基本名称错误 - 您既不应提供WEB-INF / - 部分,也不应提供资源一部分。

我们假设您的ResourceBundlePropertyResourceBundle并且由两个文件组成

  • src/main/resources/application.properties
  • src/main/resources/application_en.properties

如果您的项目由maven打包,并且文件位于<webapp-dir>/WEB-INF/classes/目录中,则您的基本名称应仅为应用程序,因为WEB-INF/classes是Classloader在哪里找到它的类(它的根目录类型)。

BTW:当它不是XML文件时,不应该命名属性文件.XML。你真的把文件称为application_en.properties.xml ??

答案 1 :(得分:1)

假设我的messages.properties类位于src/main/resources内,这是maven定义的目录。

properties_file_located_inside_maven_mvc_project

messages.properties包含以下值:

person.name=Person Name
person.age=Person Age
person.address=Person Address

所以,我在messageSource内创建了DispatcherServlet configuration file bean,如下所示,使用属性架构xmlns:p="http://www.springframework.org/schema/p"

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basename="messages"/>

我将使用spring taglib获取jsp文件中的属性值,如:

html标签上面的jsp声明:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

正文内容会像:

<form:form commandName="person">
    <table>
        <tr>
            <td><spring:message code="person.name" /></td>
            <td><form:input path="personName"/></td>
        </tr>

        <tr>
            <td><spring:message code="person.age" /></td>
            <td><form:input path="age"/></td>
        </tr>

        <tr>
            <td><spring:message code="person.address" /></td>
            <td><form:input path="address"/>
            </td>
        </tr>

        <tr>
            <td  colspan="2">
                <input type="submit" value="Set Person Details"/>
            </td>
        </tr>
    </table>
</form:form>

通过执行这些步骤,我很确定,您的javax.servlet.jsp.JspTagException已经解决了。

答案 2 :(得分:0)

<!DOCTYPE html>
<html ng-app>

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.8/angular.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" />
</head>

<body>
  <input type="text" ng-model="stuff1">
  <input type="checkbox" ng-model="stuff">
  <div ng-class="[{'text-success': stuff}, stuff1]">Stuff1!!!</div>
  <div class="{{stuff1}}" ng-class="{'text-danger': stuff}">Stuff2!!!</div>
</body>

</html>

答案 3 :(得分:-1)

我实际上在我的 java 配置类中解决了同样的问题 通过简单地设置基本名称如下

消息来源。 setBasename("WEB-INF/classes/resources/messages"); 其中,resources 是我的名为messages.properties 和messages_es.properties 的属性文件所在的包。