File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Missing message for key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Missing message for key " Watch "Missing message for key " New topic
Author

Missing message for key

Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Hi all,
I'm new to Struts. I was trying to run an example from Struts-The Complete Reference by James Holmes. I'm getting the following error.

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Missing message for key "label.search.name"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.search_jsp._jspService(org.apache.jsp.search_jsp:228)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

javax.servlet.jsp.JspException: Missing message for key "label.search.name"
org.apache.struts.taglib.bean.MessageTag.doStartTag(MessageTag.java:233)
org.apache.jsp.search_jsp._jspx_meth_bean_message_0(org.apache.jsp.search_jsp:312)
org.apache.jsp.search_jsp._jspx_meth_html_form_0(org.apache.jsp.search_jsp:267)
org.apache.jsp.search_jsp._jspService(org.apache.jsp.search_jsp:103)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.
-----------------------------------------------------
Here is my directory structure

MiniHR
|
|
index.jsp
search.jsp
WEB-INF
|
|
web.xml
struts-config.xml
lib(all jar files)
classes
|
|
ApplicationResources.properties
com
|
MiniHR
|
struts(all .class files)

----------------------------------------------------

Here is the deployment descriptor web.xml

<?xml version="1.0"?>

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>

<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>

</web-app>

-------------------------------------------------------

Here is the configuration file struts-config.xml

<?xml version="1.0"?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>

<!-- Form Beans Configuration -->
<form-beans>
<form-bean name="searchForm"
type="com.MiniHR.struts.SearchForm"/>
</form-beans>

<!-- Global Forwards Configuration -->
<global-forwards>
<forward name="search" path="/search.jsp"/>
</global-forwards>

<!-- Action Mappings Configuration -->
<action-mappings>
<action path="/search"
type="com.MiniHR.struts.SearchAction"
name="searchForm"
scope="request"
validate="true"
input="/search.jsp">
</action>
</action-mappings>

<!-- Message Resources Configuration -->
<message-resources parameter="ApplicationResources"/>

</struts-config>
-----------------------------------------------
Here is my ApplicationResources.properties
# Label Resources
label.search.name=Name
label.search.ssNum=Social Security Number

# Error Resources
error.search.criteria.missing=<li>Search Criteria Missing</li>
error.search.ssNum.invalid=<li>Invalid Social Security Number</li>
errors.header=<font color="red"><b>Validation Error(s)</b></font><ul>
errors.footer=</ul><hr width="100%" size="1" noshade="true">

I don't know where I'm going wrong. Please help.
[ January 27, 2006: Message edited by: Lalitha Vydyula ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
What this message is trying to tell you is that somewhere in your JSP, you made a reference to the message key "label.search.name", and that Struts can't find that key in your ApplicationResources.properties file.

Make sure the following entry:

label.search.name=some text

is in a file named ApplicationResources.properties, and that this file is in yourApplication/WEB-INF/classes directory.
[ January 27, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Hi Merrill,
I already have label.search.name=Name , included in my ApplicationResources.properties file & that file is in
MiniHR/WEB-INF/classes folder. Here is my search.jsp file in which I referenced the key label.search.name

Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Everything looks Ok. Have you tried restarting the application server and redeploying the application? Changes to the ApplicationResources.properties file will not take effect until the application is restarted.
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Yes, I tried that too. Still getting the same error.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
One other thing to check: Make sure your struts.jar file is in WEB_INF/lib directory and nowhere else.

See this thread.
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Sorry its my mistake, I named the file as ApplicationProperties.properties and was referecing it a ApplicationResources in configuration file. Its working now. But anyway thanks for trying Merrill.
[ January 27, 2006: Message edited by: Lalitha Vydyula ]
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
Hi,
I thought that its the name of the file. I changed the name to ApplicationResources but I forgot to change the template text(static test) in the .jsp file.That why it was running before. Now I'm trying to run the application its not working. Its giving the same error. I have struts.jar in the WEB-INF/classes/lib folder.

What could be wrong?

-Lalitha
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I changed the name to ApplicationResources but I forgot to change the template text(static test) in the .jsp file.That why it was running before.


I'm a little confused here. What do you mean by "change the template text (static test)". If it was working, why did you change it?

Also, check to see that struts.jar is not anywhere in your Application server's common or shared libraries.
Lalitha Vydyula
Ranch Hand

Joined: Jul 20, 2005
Posts: 69
I'm a little confused here. What do you mean by "change the template text (static test)". If it was working, why did you change it?


What I meant to say was in my search.jsp file I used
<td>Name:</td> - Static text(Name) rather than using
<td><bean:message key="login.search.name"/></td> - Which gets the value of the key "login.search.name" from the ApplicationResources.properties file.

I hope now its clear.
[ January 27, 2006: Message edited by: Lalitha Vydyula ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Missing message for key
 
Similar Threads
Client side form validation not working
help on taglib and properties file in struts?
Exception while running Struts
Trying to execute my First struts app but receiving "ServletException"
Configuring First Struts Application