Announcement Announcement Module
Collapse
No announcement yet.
JspTagException: No message found under code 'title' for locale 'en_US' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JspTagException: No message found under code 'title' for locale 'en_US'

    This should be so simple, but I can not get a simple <spring:message code="title"/> to work in a jsp page. I have a messages.properties file in the root of my classes folder with 1 line "title=Spring Test". I also have the following bean in my applicationContext.xml.

    Code:
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    	<property name="basename" value="messages" />
    </bean>
    When I view the page in my application, I get the error below.

    Code:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/person.jsp at line 10
    
    7: <html>
    8: <head>
    9: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    10: <title><spring:message code="title"/></title>
    11: </head>
    12: <body>
    13: <h3>Previous person was "${person.firstName} ${person.lastName}".</h3>
    
    
    Stacktrace:
    	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    
    
    root cause 
    
    javax.servlet.ServletException: javax.servlet.jsp.JspTagException: No message found under code 'title' for locale 'en_US'.
    	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
    	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
    	org.apache.jsp.WEB_002dINF.jsp.person_jsp._jspService(person_jsp.java:162)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    
    
    root cause 
    
    javax.servlet.jsp.JspTagException: No message found under code 'title' for locale 'en_US'.
    	org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:183)
    	org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
    	org.apache.jsp.WEB_002dINF.jsp.person_jsp._jspx_meth_spring_005fmessage_005f0(person_jsp.java:181)
    	org.apache.jsp.WEB_002dINF.jsp.person_jsp._jspService(person_jsp.java:75)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    	org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:236)
    	org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:257)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1183)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:902)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
    	org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

    Can someone help me discover what I am missing?


    Thanks,
    sulbig =)

  • #2
    Try this :-

    Code:
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    	<property name="basename">
            <list>
             <value>messages</value>
            </list>
            </property>
    </bean>

    Comment


    • #3
      christopher1234,

      Thank you for the response. I tried your suggestion (replaced my existing messageSource bean with yours) and still receive the same error.


      Thanks,
      sulbig

      Comment


      • #4
        I never worked with spring:message. Usually to display messages in a JSP file through a properties file i use fmt tags.

        Import the taglib
        <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

        and then use <fmt:title>

        Comment


        • #5
          Or try this :-

          Code:
          <spring:message code="${title}">

          Comment


          • #6
            I tried <spring:message code="${title}"/>, but that just gave me the same error with '' instead of 'title' in the message.

            I added the fmt taglib to my jsp page and replaced <spring:message code="title"/> with <fmt:message key="title"/>. I also added this to my web.xml...

            Code:
            <context-param>
               <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
               <param-value>messages</param-value>
            </context-param>
            ...and that worked. But I would like to be able to use the <spring:message> tag.


            Thanks,
            sulbig

            Comment


            • #7
              Same problem here

              I am having the same problem. I was hoping I could find an example on the web but found this entry instead. I am really surprised that no one uses the spring message support in jsp files. Have you had any luck getting it to work?

              -Luke

              Comment


              • #8
                Unfortunately, I did not find a resolution. I have not had much time to pursue this, either.

                I was really hoping it was doing something I was obviously doing wrong, but apparently no one knows the answer?

                Comment


                • #9
                  I got it to work

                  It looks like that even though I put the messages.properties in the WEB-INF/classes folder it wasn't getting deployed. I moved it to my root src folder and not its getting deployed and it is now working.

                  Good Luck.

                  Comment


                  • #10
                    it works if you put _en in the name of the Properties file

                    For me, I tried the worst case and gave the name of file as was being complained by the error.
                    So instead of message.properties, I put message_en.properties under the folder WEB-INF/classes...boom it worked.

                    <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
                    <property name="basenames">
                    <list>
                    <value>messages</value>
                    <value>errors</value>
                    </list>
                    </property>
                    </bean>
                    Last edited by vk2875; Dec 9th, 2009, 02:03 AM. Reason: some code left

                    Comment


                    • #11
                      Well, of course it worked, but when the users browser is set to use yet another locale, the error will most likely reappear again. The problem here is that the default language isn't kicking in.

                      You set default language with a property to the CookieLocaleResolver with deaultLocale key and a language value :
                      Code:
                      <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
                      	<property name="defaultLocale" value="en"/>
                      </bean>
                      Last edited by MiB; Oct 17th, 2011, 07:06 AM.

                      Comment


                      • #12
                        Why the messages_en_US.propertries file is required in this case? Should it be the messages.properties file that is picked in case of absence of messages_X.propertries files?

                        Comment


                        • #13
                          I have "messages_en.properties" and I suppose that if you have internationalization in your project the framework shouldn't default a language by itself, and it's reasonable that the user should explicitly tell which language to default to. In this case Spring Roo could set or encourage the user to set a default language.

                          For a newbie this is a bewildering error to encounter. For someone developing on an English system it's imagineable they could go all the way to the web before they realize that users with other locale settings in their browser don't get a default language.

                          I'd assume this is also a result of the language set by Roo in the web page templates.

                          Comment


                          • #14
                            Well, the scenario described happened in a real project and googlebot triggered a 500 internal server error on visiting the site in question as it assumed us-english language (en_us) until I made sure to give the page templates html element a lang attribute with the proper language of the page.

                            I think this is a weakness of Spring MVC and that locale settings should be set in one place only and should also change the lang attribute of the full page. It's too obscure now.

                            One simple way to detect this kind of error is to set the first language in your developer browser to something you're not likely to ever support. I went with albanian. If your page works properly the default language will still kick in, but if it doesn't it may give an error.
                            Last edited by MiB; Dec 7th, 2011, 07:46 AM.

                            Comment

                            Working...
                            X