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 Null Pointer in RequestUtils. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Null Pointer in RequestUtils." Watch "Null Pointer in RequestUtils." New topic
Author

Null Pointer in RequestUtils.

Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
When trying to access my index.jsp I get an immediate null pointer exception in RequestUtils.
I've used the <logic:redirect> tag successfully in the past but I can't see what I've done wrong this time.
My previous experience (when this was working) was with version 1.1-rc2 now I'm using 1.1.
Any help as to why this exception is happening would be much appreciated.
I've included details below.

My index.jsp is simply:
<%@ taglib uri="/tld/struts-logic" prefix="logic" %>
<logic:redirect forward="greetings" />
In my struts-config I have:
<global-forwards type="org.apache.struts.action.ActionForward">
<forward name="greetings" path="/greetings.do" redirect="false" />
</global-forwards>
<action path="/greetings"
type="org.apache.struts.actions.ForwardAction"
parameter="/WEB-INF/pages/greetingTest.jsp" />

The exception when I enter myContext/index.jsp is:
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.lang.NullPointerException
org.apache.struts.util.RequestUtils.computeURL(RequestUtils.java:521)
org.apache.struts.util.RequestUtils.computeURL(RequestUtils.java:436)
org.apache.struts.util.RequestUtils.computeURL(RequestUtils.java:396)
org.apache.struts.taglib.logic.RedirectTag.doEndTag(RedirectTag.java:294)
org.apache.jsp.index_jsp._jspx_meth_logic_redirect_0(index_jsp.java:82)
org.apache.jsp.index_jsp._jspService(index_jsp.java:58)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
I looked at the RequestUtils source and I think that the MODULE_KEY attribute (request and application scope) is null. However
I can't figure out why my configuration would be causing this.
Rich
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

I'm having a hard time figuring out what you want to do here. The best I can figure is that you do not want the user's address bar to show .do at the end.
I don't think a request will hit the Struts Controller unless it follows the pattern mapped to the Controller in your web.xml. Maybe you could change the pattern from *.do to something else, like myapp/*
Wouldn't hurt to at least see if that's the problem. Good luck Rich!


A good workman is known by his tools.
Rich Smyth
Ranch Hand

Joined: May 30, 2002
Posts: 87
I'm having a hard time figuring out what you want to do here.

I want to test the welcome file defined in my web.xml
<welcome-file>/index.jsp</welcome-file>
When I entered myContext/ on the address line I got the error described I my original email.
Rich
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Oh. Get rid of the global-forwards' forward and have index.jsp forward to greetings.do instead of just greetings.
The Struts controller will direct this to the action mapped to the path /greetings
The web.xml sees that it ends in .do and sends it to the Struts Controller.
The Struts Controller then knows to remove the .do and finds the mapping of / + the request sans .do
In this case greetings.do would be directed automagically to the action mapped with the path="/greetings"
Right now your jsp is forwarding to "greetings". Because it does not end in .do, it never gets sent to the Struts Controller and so the struts-config never comes in to play.
Jo�l Rouiller
Greenhorn

Joined: May 06, 2004
Posts: 1
Dear Rich,
I had the exactly same problem and found a solution (for me)!
I develop my web application in Eclipse with Tomcat 5.0.19. Trying to deploy it with Tomcat 4.1.8 and 4.1.30 results in the problem you encountred.
So, if you develop/run with Tomcat try to upgrade to 5.0.19 if you can.
Best regards,
Jo�l
Dave Knipp
Ranch Hand

Joined: Oct 14, 2003
Posts: 146
I am getting the same error when using logic:redirect. I get the request utils null pointer no matter if i use a global forward or a direct forward to the action itself.

Has anyone figured this out other than changing server versions? Is it api related? Maybe there are some struts dependent libraries that are out of sync with what is expected?

Any help would be great.

Thansk,
Dave


SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
Monica Singhal
Greenhorn

Joined: Dec 09, 2005
Posts: 3
I had the similar problem. Everything worked fine yesterday when i left and today when i tried to run the application it just gave that error.

I couldnt find any reason behind it. As code was perfectly alright. Tried a couple of things(even rebooted the computer), nothing worked.

I was using eclipse as the IDE for my application so finally, "clean" the project and run it again. It worked for me.

May be its a bug in Tomcat. I am not sure if they have handled it in new versions or not. I was however using Tomcat 5.0.28
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer in RequestUtils.