my dog learned polymorphism*
The moose likes Struts and the fly likes Struts Problem in the March Article Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Problem in the March Article" Watch "Struts Problem in the March Article" New topic
Author

Struts Problem in the March Article

Remo Burkhard
Greenhorn

Joined: Feb 16, 2002
Posts: 12
Hello I tried the excellent Javaranch Newsletter Example http://www.javaranch.com/newsletter/Mar2002/newslettermar2002.jsp
For some reason I always have the following error:
when I try to access LoginView.jsp on Tomcat 4
---------------------------
javax.servlet.ServletException: Missing message for key Hello
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:463)
at
...
-------------------------------------
It seems to me that I need to enter some information in a xml file or somewhere else but I dont get it.
Can someone help me and explain where I have to change files and where to put them.
Thank you
Remo
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Double check your login view and make sure that you don't have a key="Hello" anywhere.
Also make sure you have MessageResources.properties in your c:\tomcat\webapps\struts\WEB-INF\classes\test\struts directory.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Remo Burkhard
Greenhorn

Joined: Feb 16, 2002
Posts: 12
still does not work.
It is at the right place and my LoginView does not have a key="Hello". Here the code
<!-- LoginView.jsp -->
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %>
<HTML>
<HEAD><TITLE><struts:message key="title.login" /></TITLE></HEAD>
<BODY>
<struts:message key="heading.login" />
<html:errors />
<html:form action="/login">
<p>
<struts:message key="label.userId" />:
<html:text property="userId" size="10" />
<br>
<struts:message key="label.passWord" />:
<html assword property="passWord" size="10" />
<br><br>
<html:submit>
<bean:message key="button.submit" />
</html:submit>
</html:form>
</BODY>
</HTML>

Where is the information for key="heading.login" saved?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Remo Burkhard:
Where is the information for key="heading.login" saved?
That is in the MessageResources.properties in your c:\tomcat\webapps\struts\WEB-INF\classes\test\struts directory
[ May 13, 2002: Message edited by: Thomas Paul ]
Mart?n L?pez
Greenhorn

Joined: Apr 18, 2002
Posts: 3
I think you should see in the web.xml file where the ApplicationResources must be store, you can see that in the next lines in the web.xml.
<init-param>
<param-name>application</param-name>
<param-value>ApplicationResources</param-value>
</init-param>
this said that the ApplicationResources.property is in the ..../WEB-INF/clases directory.
Then in the ApplicationResources you should see
index.logon=something.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
I was just working thru the example in the March article(which was excellent, by the way) and ran into the same problem the original poster had. I am running Tomcat 4.1.12.
Here is the exception:
org.apache.jasper.JasperException: Missing message for key title.login
It looks as if Tomcat can't find my MessageResources.properties file.
My web.xml has this:
<init-param>
<param-name>application</param-name>
<param value>test.struts.MessageResources</param-value>
</init-param>
And my MessageResources.properties file is under %tomcat%/webapps/struts/WEB-INF/classes/test/struts/
Has anyone else had this problem?
I even tried moving MessageResources directly under my classes directory and changing the web.xml application value to MessageResources, but still the same error.
Any help would be appreciated.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
If you've followed the advice in this thread already then something's really screwed up. Have you double checked that your .properties file really is where it is meant to be, that your web.xml is too? Are you deploying these or working directly in the appserver directory?
You could try deleting or commenting out the message tab with the key="title.login" and seeing what happens. If it then throws an exception with the next message tag, missing the next key, then it really can't find your .properties file.


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Yes, I did try to remove the first message key and I got an error on the next key. The properties file is in the correct location.
Also, I even deployed the struts-example war(that also uses a properties file) and tomcat couldn't find that properties file either. I got the same 'Missing message key' error. This seems really strange.
I am running this on xp... I am going to try on another machine with 2k.
Anyone have any other suggestions?
Thanks, Chad
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Ok. I installed struts and tomcat on my laptop running windows 2k, and everything worked! I have tomcat 4.1.12 on both machines and all environment variables are exactly the same on both machines. I am stumped. The xp machine is running Internet Explorer 6.0 and the 2k machine is using version 5.50. Those are the only difference I can see between the two machines.
Has anyone else had problems running struts and tomcat on xp with IE6?
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Me not. I am using Tomcat 4.05, Windows XP Professional, IE 6.
Never run into the MessageRessources.properties problem you reported. Maybe only with Tomcat 4.12 and W.XP? Sounds strange.
Axel
[ November 17, 2002: Message edited by: Axel Janssen ]
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
It appears that tomcat isn't locating any class file mappings defined in my struts-config.xml as well. I tried to run the struts-example-taglib...when I click on html:link, which according to struts-config is defined as:

I get this exception: "Exception creating bean of class org.apache.struts.webapp.exercise.TestBean: java.lang.ClassNotFoundException"
TestBean is defined as:

So I am having more problems than just dealing the properties file.
I have checked everything I know to check and I can't find anything wrong with my tomcat/struts configuration. I just copied the struts-example-taglib war into the webapps directory, then restarted tomcat. All the directories under struts-example-taglib were then created correctly, and the directory structure matches the paths defined in struts-config.xml.
I'm running out of ideas, but I don't think I will be able to drop this until I get it working!
Any thoughts would be appreciated
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
I downloaded Resin last night and tried to run it using struts. Got the same error. So now I can say with some confidence that the problem I am having is with struts only.
Now I'm racking my brain trying to figure out what I am missing in my struts installation that would cause it to fail on xp, but not on Win2k. Any ideas, please post them.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
Could it be something to do with the language settings? Could your XP machine be causing struts to look for the localized versions of the resource file, i.e. ApplicationResources_en.properties?
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I'll try it tonight on my XP box and see if I run into the same error. I was able to successfully run it with Tomcat but I don't remember which version.


Matthew Phillips
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Thanks Matthew, I'm anxious to see if anyone else can recreate this problem.
Adam, I'm going to create an _en version of the properties file and see what happens.
Thanks.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I just copied the code verbatim from the article and had no problem running it with Resin on Windows XP. I used Struts 1.1. I believe it is beta 2, but I am not 100% sure of that. The error sounds like it cannot find the MessageResources.properties file. Make sure that it it in the proper folder and that it is properly identified in web.xml.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Thanks for your help.
I have verified the web.xml and properties file location is correct.
I'm also assuming that you can deploy struts-example.war on Resin with no problems??
When I deploy it(copied struts-example.war to webapps directory), I get the same exception(javax.servlet.jsp.JspException: Missing message for key index.title.)
When I deploy struts-documentation.war, It works perfectly, because it does not actually use struts.
This tells me that I am deploying these war files correctly, but that any webapp that uses struts fails. I still have no idea why.
This is really frustrating!
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I don't know if this will make a difference, but are you using Resin or ResinEE? I used ResinEE.
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
I had another thought. Is struts.jar showing up in the classpath of Windows XP? I seem to remember having problems after I put it in my environment variables and then running it with that still there.
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
I used ResinEE. I'm pretty sure I have tried to run it with and without struts.jar in the classpath, but that's a good idea. I will try that again tonight.
Chad
[ November 21, 2002: Message edited by: Chad McGowan ]
Chad McGowan
Ranch Hand

Joined: May 10, 2001
Posts: 265
Wow. I finally got it working.
I checked and found that struts.jar was not in my classpath, so after saying a few choice words, I looked back through the Resin console to see if something stood out.
Well, I found several register: statments that were referencing my JAVA_HOME/jre/lib/ext/struts.jar file.
I removed that from my ext directory and like magic, it worked.
Thanks for your suggestion; that got me thinking about other locations for struts.jar, which eventually helped me fix the problem.

Now, the question is, why is Resin(and I'm assuming Tomcat was doing the same thing, I'll test that later) looking in my JAVA_HOME for struts.jar when it is located under WEB-INF/lib?
dimitar georgievski
Greenhorn

Joined: Apr 17, 2003
Posts: 1
although this tread is old i'll put some comments on it. i came across the same problem on JBoss 3.0/Tomcat4.1.12 running on Win2K. someone searching the web might find this helpful and doesn't have to lose time for an answer.
If you take a look at the Struts User/developer guide you will notice that they are recommending struts.jar to be always in the WEB-INF/lib directory of the application. The reason for that is the class loader used to load this jar file. Apparently if you put in the classpath or in the lib folder of the application server (JBoss) your application files and struts.jar are loaded under different contexts. The outcome is your application cannot reference some of the resources. The point is keep struts.jar in the WEB-INF/lib folder!
Patrick Loretz
Greenhorn

Joined: Apr 23, 2003
Posts: 2
I found this Struts article very helpful in getting started, better than anything else I've read. I also found this thread helpful in dealing with the problem of where to put struts.jar (and where not to put it).
What I am now running into with this example seems to be a problem with the HttpServletRequest information.
The userId and passWord I enter do not make it to the LoginBean.
This initially showed itself as a java.lang.NullPointerException in the
if (!userId.equals(passWord)) statement
A simple println showed that both useId and passWord are null prior to that if statement.
LoginForm is happy with the values entered, as it successfully checks for null or spaces.
I am using Tomcat 4.0.1 and Struts 1.0.2 on both Linux and Windows with the same results.
Any ideas would be appreciated.
Thank you,
Patrick
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
The LoginForm.java has already checked to make sure that the userid and password weren't null as entered so we know it didn't come in that way.
What are in userid and password when you run the LoginBean's setParameters method? Are you mistakenly storing them as method variables? Is LoginAction running the LoginBean's setParameters method?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
And thanks for the kind words about the article!
Patrick Loretz
Greenhorn

Joined: Apr 23, 2003
Posts: 2
I found the problem, it seems that LoginBean.java in the strutsfiles.zip is different from that in the listings.
The .zip version is storing them as method variables, which is what messed me up (good lesson for me though).
That is the 2nd difference between the listings and the .zip file I found. The other was with the MessageResources.properties file missing a few entries.
Both had me banging my head against the wall, but also helped me understand a bit more about what is actually going on.
Thanks again for the great examples and article.
[ April 23, 2003: Message edited by: Patrick Loretz ]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
zip file? I didn't even know there was a zip file! I have made changes to the code in the last year without realizing that there was a zip file so maybe it is time to either fix it or remove it!
Thanks for pointing this out to me!!!
Mark Day
Greenhorn

Joined: Jan 04, 2004
Posts: 1
Originally posted by Thomas Paul:
That is in the MessageResources.properties in your c:\tomcat\webapps\struts\WEB-INF\classes\test\struts directory
[ May 13, 2002: Message edited by: Thomas Paul ]

Hi,
This problem is not very well documented and all the postings ive read so far
have been unclear or plainly have not worked in solving this issue.
step 1. make sure your struts-config.xml has the following line in it
<message-resources parameter="demo.ApplicationResources" />
demo is the package name. the .properties is implied and NOT NEEDED.

step 2. place the ApplicationResources.properties file under your package in the
src section of your project.
step 3. copy the following jar files from your struts 1.0/1.1 folder
\jakarta-struts-1.1\lib\commons*.jar to the lib directory of your
application. (7 files to copy in all).
copy \jakarta-struts-1.1\lib\struts.jar to the lib directory as well.
note : these jar files must be in the lib directory to stop this error
please let me know if this solved the problem mark@jsday.freeserve.co.uk
good luck
mark day
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Problem in the March Article