• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with a global forward

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this in a jsp page:
<LI><html:link forward="CreateRequirement">Create New Requirement</html:link></LI>
Which causes this exception when the page is loaded:
java.lang.NullPointerException
at org.apache.struts.util.RequestUtils.computeURL(RequestUtils.java:521)
I have this in my global forwards:
<forward name="CreateRequirement" path="createRequirement.do"/>
Now I know findforward returns a null if there's no mapping for the given forward, but there is. Can anyone point out my doubtless obvious mistake ?
Thanks
Edward
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
try to add "/" to the path attribute
<forward name="CreateRequirement" path="/createRequirement.do"/>
rgds
beN
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, tried that. The problem isn't that the wrong URL is being generated but rather that it doesn't seem to be finding the forward at all.
Edward
 
Bernardus Irmanto
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well..
if you set the struts config properly, you should be able to execute the action you specified in the path attribute.
BTW., the path attribute should begin with a slash("/") character. It represent the module-relative or context relative path to the resource that is encapsulated by the logical name. If the path is to be considered context-relative, then the contextRelative attribute should be set to true...

rgds
beN
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Edward Kenworthy:
I have this in a jsp page:
<LI><html:link forward="CreateRequirement">Create New Requirement</html:link></LI>
Which causes this exception when the page is loaded:
java.lang.NullPointerException
at org.apache.struts.util.RequestUtils.computeURL(RequestUtils.java:521)
I have this in my global forwards:
<forward name="CreateRequirement" path="createRequirement.do"/>
Now I know findforward returns a null if there's no mapping for the given forward, but there is. Can anyone point out my doubtless obvious mistake ?
Thanks
Edward


You must have an *action* defined *createRequirement* in the strust-config.xml.
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hafizur Rahman:

You must have an *action* defined *createRequirement* in the strust-config.xml.


<sigh> I have. The problem is not that no resource is defined, but rather generating the URL fails (as per the exception). The problem appears to be that findforward isn't finding my forward and is returning null.
Now, is there anyone that knows what they're talking about that can help me ?
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh and a correction, you do not have to have an action defined in order to define a forward, that's what global-forwards are.
 
Hafizur Rahman
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Plz show ur struts-config file. Hope we can locate..
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hafizur Rahman:
Plz show ur struts-config file. Hope we can locate..


Here you go (I'm using xdoclet):
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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>
<!-- ========== Data Sources Definitions =================================== -->
<!--
Define your Struts data sources in a file called struts-data-sources.xml and place
it in your merge directory.
-->
<!-- ========== Form Bean Definitions =================================== -->
<form-beans>
<form-bean
name="requirement.Create"
type="info.kenworthy.reqxml.web.forms.CreateRequirementForm"
/>
<!--
If you have non XDoclet forms, define them in a file called struts-forms.xml and
place it in your merge directory.
-->
</form-beans>
<!-- ========== Global Exceptions Definitions =================================== -->
<!--
Define your exceptions in a file called global-exceptions.xml and place
it in your merge directory.
-->
<!-- ========== Global Forward Definitions =================================== -->
<global-forwards>
<forward name="CreateRequirement" path="createRequirement.do"/>
</global-forwards>
<!-- ========== Action Mapping Definitions =================================== -->
<action-mappings>
<action
path="/createRequirement"
type="info.kenworthy.reqxml.web.actions.CreateRequirementAction"
name="requirement.Create"
scope="request"
input="/WEB-INF/jsp/createRequirement.jsp"
unknown="false"
validate="true"
>
<forward
name="success"
path="/WEB-INF/jsp/requirementCreated.jsp"
redirect="false"
/>
</action>
<!-- If you have non XDoclet actions, define them in a file called struts-actions.xml and place it in your merge directory. -->
</action-mappings>
<!-- Define your Struts controller in a file called struts-controller.xml and place it in your merge directory. -->
<!-- Define your Struts message-resources in a file called struts-message-resources.xml and place it in your merge directory. -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
 
Hafizur Rahman
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From my understanding, everything is OK. probably u need to update ur struts.
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking in the Struts source, this is your problem line:As you see, a NullPointerException is possible only if "config" is null. This variable represents the Struts configuration and is loaded here:The configuration is bound in the request; if it can't be found there, it is pulled from the application scope. I haven't investigated any further than this, but my best guess at this point is that your request is going straight to the JSP without going through the Struts controller, thereby not giving Struts the chance to bind the configuration object. This page is the very first thing you're requesting after restarting the web-app, and you have not configured the Struts ActionServlet as an initialisation servlet.
The fix is simple. Turn ActionServlet into an initialisation servlet. In addition, it is often best to route every request through the controller, even if all you're doing is a simple forward to the view page, so consider doing that as well.
- Peter
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this problem at the moment but ONLY when I run tomcat5 under jre 1.3.1_08. If I run tc under a 1.4 jre (j2sdk1.4.2_05 to be precise) the error disappears.

Any ideas?
 
reply
    Bookmark Topic Watch Topic
  • New Topic