wood burning stoves 2.0*
The moose likes Spring and the fly likes <spring:message tag not reading the properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Spring
Bookmark "<spring:message tag not reading the properties file" Watch "<spring:message tag not reading the properties file" New topic
Author

<spring:message tag not reading the properties file

Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
Hi everyone,
I am getting the following exception when I try display the labels on my login page using the <spring:messages tag.


javax.servlet.jsp.JspTagException: No message found under code 'user.id' for locale 'en_NZ'.
org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:183)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77)
org.apache.jsp.jsp.login_jsp._jspx_meth_spring_005fmessage_005f1(login_jsp.java:286)
org.apache.jsp.jsp.login_jsp._jspService(login_jsp.java:131)
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)

Login.jsp located in application/jsp
<td class="verbatimStyle" width="40%" align="right"> <spring:message
code="user.id" />: </td>

messages.properties located in web-inf/classes
user.id = User ID

spring.tld located in web-inf
<tag>
<name>message</name>
<tag-class>org.springframework.web.servlet.tags.MessageTag</tag-class>
<body-content>JSP</body-content>

<description>
Retrieves the message with the given code, or text if code isn't resolvable.
The HTML escaping flag participates in a page-wide or application-wide setting
(i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
</description>

<attribute>
<name>message</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>A MessageSourceResolvable argument (direct or through JSP EL).</description>
</attribute>

<attribute>
<name>code</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The code (key) to use when looking up the message.
If code is not provided, the text attribute will be used.</description>
</attribute>

<attribute>
<name>arguments</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set optional message arguments for this tag, as a
(comma-)delimited String (each String argument can contain JSP EL),
an Object array (used as argument array), or a single Object (used
as single argument).</description>
</attribute>

<attribute>
<name>argumentSeparator</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The separator character to be used for splitting the
arguments string value; defaults to a 'comma' (',').</description>
</attribute>

<attribute>
<name>text</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Default text to output when a message for the given code
could not be found. If both text and code are not set, the tag will
output null.</description>
</attribute>

<attribute>
<name>var</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The string to use when binding the result to the page,
request, session or application scope. If not specified, the result
gets outputted to the writer (i.e. typically directly to the JSP).</description>
</attribute>

<attribute>
<name>scope</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>The scope to use when exporting the result to a variable.
This attribute is only used when var is also set. Possible values are
page, request, session and application.</description>
</attribute>

<attribute>
<name>htmlEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set HTML escaping for this tag, as boolean value.
Overrides the default HTML escaping setting for the current page.</description>
</attribute>

<attribute>
<name>javaScriptEscape</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
<description>Set JavaScript escaping for this tag, as boolean value. Default is false.</description>
</attribute>
</tag>


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

<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"
singleton="true">
<property name="mappings">
<props>
<prop key="/login.do">loginController</prop>

</props>
</property>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
singleton="true">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>

Server: Tomcat 6.0
jdk1.6.0_15
Spring.jar
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.5.0_08-b03 (Sun Microsystems Inc.)
Implementation-Title: Spring Framework
Implementation-Version: 2.0
Spring-Version: 2.0
Premain-Class: org.springframework.instrument.InstrumentationSavingAgent

I am not sure where am I going wrong.

Anyone please help me fix this issue.
Many thanks
Kavitha
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

This thread on the Spring forums discusses some similar problems and gives some solutions.

Assuming that the root folder of your web application is signified by %ROOT% - (i.e. - %ROOT%/WEB-INF/classes would be your classes directory)

Is your Login.jsp in %ROOT%/application/jsp? or %ROOT%/jsp?

If it's the first, that may be your problem - your ViewResolver is assuming your views will be in %ROOT%/jsp/

So the solution would be to make the paths match in both - or to define your messageSource bean in applicationContext.xml rather than <application>-servlet.xml - that puts the messageSource bean in the root Spring context so it can be found even if your jsp isn't mapped to a specific <application>-servlet.xml context.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
I have been working the whole day yesterday on resolving this one. Now its working. Unfortunately I just searched for some sample code from the net and deployed it. It works fine on that application. Since I am just starting my project, I am fine to alter the folder structure a bit, so I am following that. To your question, suppose accountManagement is my application. the folderstructure goes like this

webapps/accountmanagement/jsp ->where all my jsps reside that has spring:message tag
webapps/accountmanagement/WEB-INF -> where my accountmanagement-servlet.xml resides
webapps/accountmanagement/WEB-INF/classes -> where my messages.properties was placed
webapps/accountmanagement/WEB-INF/lib -> where my spring-jar was residing.

As you said I also tried with applicationcontext.xml. It doesnt work.
What worked was, moving the jsp folder inside the WEB-INF folder something like
webapps/accountmanagement/WEB-INF/jsp

So that resolved the issue.
Thanks for your help.
Kavita
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: <spring:message tag not reading the properties file