Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Help needed with struts

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a newbie to struts and I am trying to send a request to a an action class and i get an error and I cant figure out why.
The http link on which i am clicking looks like given below.
http://localhost:9080/ABCPortalWeb/PCardCreatePublicAction.do
The action mapping I have is as given below
<action path="/PCardCreatePublicAction"
type="com.siemens.ssl.sas.pcard.create.web.PCardCreateRequestPublicAction" input="/PCardCreateRequestPublic.jsp">
<forward name="500101" path="/pcard/create/jsp/PCardCreateRequestPublic.jsp">
</forward>
</action>
I get the following error in the console of Websphere Application Developer
[2/21/04 11:28:45:125 EST] 27af6a74 WebGroup E SRVE0026E: [Servlet Error]-[action]: java.lang.NullPointerException
at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1396)
at com.ibm.ws.webcontainer.webapp.WebApp.getRequestDispatcher(WebApp.java:1376)
at org.apache.struts.action.ActionServlet.processActionForward(ActionServlet.java:1751)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1596)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:492)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:258)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:872)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:491)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:173)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:199)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:331)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:432)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:343)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:592)
I really have no clue whats happening. I tried to use a print statement in the action class and I find that the print statement is never called.
Can someone help me on this ?
regards
sreekanth menon
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sreekanth,
I will give a small example to show how you have to map the action in your struts
Suppose you have a jsp called login.jsp
in that you will have a formaction tag like
<html:form action="/login" >
here your rest of the code for your jsp
</html:form>

for this jsp you will have a actionFormBean class . Let it be LoginForm
first you map this as
<form-bean name="loginForm" type="mypackahe.LoginForm"/>
After this you map your action class
<action mapping="/login" type="mypackage.LoginAction" name="loginName" input="/login.jsp" scope="request">
<forward name="success" path="/menu.jsp"/>
</action>
Here your path in the action mapping should match with your form action and name with formbean name in the formbean mapping.
You can replace the package structureaccording to your package structure/
Hope this will help you.
You will get more information if you go through jakarta site
All the best

poornima
 
sreekanth menon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks poornima
Though my problems are not exactly solved.. I am making some progress..
Could u tell me what the parameter="public"
will do for the given configuration shown below ?
<action mapping="/login" type="mypackage.LoginAction" name="loginName" input="/login.jsp" scope="request"
parameter="public">
<forward name="success" path="/menu.jsp"/>
</action>
 
sreekanth menon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again. If i dont mention that parameter .. I dont get the NullPointerException. So any idea whats happening ?
 
poornima balagopal
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sreekanth,
In the action mapping we give parameter if we have more than one methods in the action class. I mean if we use DispatchAction class instead of Action class while creating Action classes(Normally we extend Action class only )we can create more than one method in the action class. For example to handle delete,update and insert actions different jsps you dont need to create that many action classes. All you can handle in one action class
Just see the example i am giving
public class MyAction extends DispatchAction
{
public ActionForward insertDetails(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOeption,ServletException
{
== your code to do the insert data==
return mapping.findforward("inserted");
}
public ActionForward deleteDetails(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws IOeption,ServletException
{
== your code to do the delete data==
return mapping.findforward("deleted");
}
}
Like this you can create your method for different jsps or different actions of your jsp .
In the jsp while you give form action you have to give as
<html:form action="/insert?option=insertDetails">
</html:form>
You can give whatever you want instead of option . but you should give the same in your action mapping as parameter.
IF you want to know how Dispatch Action class works and how the mapping has to be done, please go throught onjava.com site . It is really good. Stil you are not clear , i will try my level best to help you
If you are using only execute method only no need of giving the parameter attribute in the action mapping.
All the best try this
poornima
 
poornima balagopal
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sreekanth,
I forgot onething to mention. In the jsp in the form action we give the
option or public parameter to specify which action class method to be used for that particular form action .
If the jsp is using for insertion in the form action tag you have to give the insertDetails () method of the action class.
We use DispatchAction class mainly to avoid no of classes using. you have to import the DisatchAction class if you are using this.
And dispatchAction class is with Struts 1.1 not 1.0
 
sreekanth menon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Poornima
I tried making a post here
The < and > signs were creating problems for me to post it in here.. so I have mailed it ur yahoo mail id. If u think this is going to be useful to someone else.. please do post it here.. if u know a work around.. I tried < and > it didnt work.
Thanks and regards
sreekanth menon
 
Trust God, but always tether your camel... to this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic