You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by David White <wh...@home.com> on 2001/07/13 22:20:49 UTC

What If Resources Are Not Found?

I am having difficulty running a struts web-app via JBuilder 5. I do not
seem to be getting my resource file loaded/found. However, this is not
really a JB question...

It seems that struts looks for the configured resource file (I see the
message in the log). However, it does NOT seem to do anything if that
file is not found. It seems to just march merrily on only to fail later
when the application asks for a resource and it is not found.

I have looked a bit at the source code for the action servlet and I
cannot see anywhere in the resource factory stuff where it will fail if
the configured file is not found.

Is this intended?

Thanks,

David

RE: What If Resources Are Not Found?

Posted by eden <ed...@jamethial.ath.cx>.
Well, I'm not sure what to tell you, David, except to make sure you *do*
have that resource file in place.  It's like anything else in code, you need
to check if something's there before you use it.  You might want to add an
if !Resource == null then <bean:message>.  But I'm sure you've already
thought of that.  As far as I'm aware, the logic tag is the Struts mechanism
to prevent a null pointer in a non-form message call, but I have found that
that's enough to do the trick.

Forgive me for not being of more help.

Melissa

-----Original Message-----
From: David White [mailto:whitedavidp@home.com]
Sent: Sunday, July 15, 2001 5:22 PM
To: struts-user@jakarta.apache.org
Subject: Re: What If Resources Are Not Found?


Thanks for the response. My comments follow yours...

eden wrote:
>
> Struts gives you the option of planting a trap for that sort of thing
(i.e.
> missing resource files ) in the jsp itself, via the logic tag
(present/not
> present),

By this, I assume you mean this sort of thing (which I have already
cut/pasted from the sample struts app):

<logic:notPresent name="org.apache.struts.action.MESSAGE"
scope="application">
  <font color="red">
    ERROR:  Application resources not loaded -- check servlet container
    logs for error messages.
  </font>
</logic:notPresent>

As I indicated, I already have this check in place for the jsp in
question. However, now that I look at the sample page from when I stole
this stuff, I wonder how it could ever work. Note that the above code
follows AFTER this line: <title><bean:message
key="index.title"/></title>. Now, if the application resources are NOT
found, how can this line be resolved? I find that an exception gets
thrown due to failure to get a message with the specified key. In this
case, how does execution ever get to the logic test? Im my case, it does
not.

In addition, I find that if struts does NOT find the application
resources file, a PropertyMessageResources is still associated with the
application scoped variable keyed to org.apache.struts.action.MESSAGE.
However, when I try to access my message via its key, null is returned.
I have no idea what is being placed in the application scope variable
except that it is an instance of the PropertyMessageResources class.
Anyone know what this is?

 or the ever useful ActionErrors object returned from the validate
> method of a class that extends 'ActionForm'.  You can do your resource
file
> validation there as well, so the code never executes past the form bean if
> the file isn't in place.

Of course, this is another way to do it. Except that I am simply trying
to access my index.jsp page which is NOT a form.

>
> Remember, and Application type resource files (like string resource files,
> for eg) must be present in the class path in order to be used.  Use ant to
> copy any resource files into your WEB-INF/Classes dir to make sure you
don't
> get any errors.

I have checked and the file ApplicationResources.properties is being
copied into the right place in the war file. I belive that the initial
problem I am having is with JBuilder 5. However, if I explicitly try to
break struts by removing the named resource file from the .war file, I
get the above described behavior and struts just marches merrily on.

Any idea? Do you get the same behavior?

Thanks,

David

>
> Cheers!
> Melissa
>
> -----Original Message-----
> From: David White [mailto:whitedavidp@home.com]
> Sent: Friday, July 13, 2001 4:21 PM
> To: struts-user@jakarta.apache.org
> Subject: What If Resources Are Not Found?
>
> I am having difficulty running a struts web-app via JBuilder 5. I do not
> seem to be getting my resource file loaded/found. However, this is not
> really a JB question...
>
> It seems that struts looks for the configured resource file (I see the
> message in the log). However, it does NOT seem to do anything if that
> file is not found. It seems to just march merrily on only to fail later
> when the application asks for a resource and it is not found.
>
> I have looked a bit at the source code for the action servlet and I
> cannot see anywhere in the resource factory stuff where it will fail if
> the configured file is not found.
>
> Is this intended?
>
> Thanks,
>
> David


Re: What If Resources Are Not Found?

Posted by David White <wh...@home.com>.
Thanks for the response. My comments follow yours...

eden wrote:
> 
> Struts gives you the option of planting a trap for that sort of thing (i.e.
> missing resource files ) in the jsp itself, via the logic tag  (present/not
> present),

By this, I assume you mean this sort of thing (which I have already
cut/pasted from the sample struts app):

<logic:notPresent name="org.apache.struts.action.MESSAGE"
scope="application">
  <font color="red">
    ERROR:  Application resources not loaded -- check servlet container
    logs for error messages.
  </font>
</logic:notPresent>

As I indicated, I already have this check in place for the jsp in
question. However, now that I look at the sample page from when I stole
this stuff, I wonder how it could ever work. Note that the above code
follows AFTER this line: <title><bean:message
key="index.title"/></title>. Now, if the application resources are NOT
found, how can this line be resolved? I find that an exception gets
thrown due to failure to get a message with the specified key. In this
case, how does execution ever get to the logic test? Im my case, it does
not.

In addition, I find that if struts does NOT find the application
resources file, a PropertyMessageResources is still associated with the
application scoped variable keyed to org.apache.struts.action.MESSAGE.
However, when I try to access my message via its key, null is returned.
I have no idea what is being placed in the application scope variable
except that it is an instance of the PropertyMessageResources class.
Anyone know what this is?

 or the ever useful ActionErrors object returned from the validate
> method of a class that extends 'ActionForm'.  You can do your resource file
> validation there as well, so the code never executes past the form bean if
> the file isn't in place.

Of course, this is another way to do it. Except that I am simply trying
to access my index.jsp page which is NOT a form.

> 
> Remember, and Application type resource files (like string resource files,
> for eg) must be present in the class path in order to be used.  Use ant to
> copy any resource files into your WEB-INF/Classes dir to make sure you don't
> get any errors.

I have checked and the file ApplicationResources.properties is being
copied into the right place in the war file. I belive that the initial
problem I am having is with JBuilder 5. However, if I explicitly try to
break struts by removing the named resource file from the .war file, I
get the above described behavior and struts just marches merrily on.

Any idea? Do you get the same behavior?

Thanks,

David

> 
> Cheers!
> Melissa
> 
> -----Original Message-----
> From: David White [mailto:whitedavidp@home.com]
> Sent: Friday, July 13, 2001 4:21 PM
> To: struts-user@jakarta.apache.org
> Subject: What If Resources Are Not Found?
> 
> I am having difficulty running a struts web-app via JBuilder 5. I do not
> seem to be getting my resource file loaded/found. However, this is not
> really a JB question...
> 
> It seems that struts looks for the configured resource file (I see the
> message in the log). However, it does NOT seem to do anything if that
> file is not found. It seems to just march merrily on only to fail later
> when the application asks for a resource and it is not found.
> 
> I have looked a bit at the source code for the action servlet and I
> cannot see anywhere in the resource factory stuff where it will fail if
> the configured file is not found.
> 
> Is this intended?
> 
> Thanks,
> 
> David

RE: What If Resources Are Not Found?

Posted by eden <ed...@jamethial.ath.cx>.
Struts gives you the option of planting a trap for that sort of thing (i.e.
missing resource files ) in the jsp itself, via the logic tag  (present/not
present), or the ever useful ActionErrors object returned from the validate
method of a class that extends 'ActionForm'.  You can do your resource file
validation there as well, so the code never executes past the form bean if
the file isn't in place.

Remember, and Application type resource files (like string resource files,
for eg) must be present in the class path in order to be used.  Use ant to
copy any resource files into your WEB-INF/Classes dir to make sure you don't
get any errors.

Cheers!
Melissa

-----Original Message-----
From: David White [mailto:whitedavidp@home.com]
Sent: Friday, July 13, 2001 4:21 PM
To: struts-user@jakarta.apache.org
Subject: What If Resources Are Not Found?


I am having difficulty running a struts web-app via JBuilder 5. I do not
seem to be getting my resource file loaded/found. However, this is not
really a JB question...

It seems that struts looks for the configured resource file (I see the
message in the log). However, it does NOT seem to do anything if that
file is not found. It seems to just march merrily on only to fail later
when the application asks for a resource and it is not found.

I have looked a bit at the source code for the action servlet and I
cannot see anywhere in the resource factory stuff where it will fail if
the configured file is not found.

Is this intended?

Thanks,

David