• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Action going nowhere

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have set a small struts application

I cannot figure where my actionmapping is pointing

The struts-config.xml is:

<struts-config>
<data-sources/>
<form-beans>
<form-bean name="GetNameForm" type="sample.GetNameForm"/>
</form-beans>
<global-exceptions/>
<global-forwards>
<forward name="getName" path="inputname.jsp"/>
</global-forwards>
<action-mappings>
<action name="GetNameForm" path="/greeting" scope="request" type="sample.GreetingAction">
<forward name="sayHello" path="greeting.jsp"/>
</action>
</action-mappings>
<controller/>
</struts-config>

The setup i got is:
Apache Software Foundation\Tomcat 5.5\webapps\StrutsHello

and under StrutsHello

WEB-INF
classes
lib
pages/
and under pages i got
index.jsp
inputname.jsp
greeting.jsp


I got it working from index.jsp(which just has a logic redirect forward) to the inputname.jsp
and when i press the submit button is seems to go to the greeting.do and does nothing.

(ie it gets to http://localhost:8080/StrutsHello/pages/inputname.jsp then pressing submit button with html:form action="/greeting.do"

it goes to : http://localhost:8080/StrutsHello/greeting.do and does nothing.

Any suggestions to what i am doing wrong?

Thanks

Anil
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that at the end of the execute() method of GreetingAction you have the statement:

return mapping.findForward("sayHello");

where mapping is the variable name for the ActoinMapping object passed in as a parameter to the execute method.
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Merrill,

I do have return mapping.findForward("sayHello") in the execute() method.

I was more concerned whether i placed the everything in the right structure.

Anil
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try with this
In the forward attribute check the path attribute starts with forward slash(/) for <global-forwards> as well as <action> forwards

<forward name="getName" path="/inputname.jsp"/>
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sai,

Thanks for your suggestion.
I tried it but the same issue exist.
it just hangs on
http://localhost:8080/StrutsHello/greeting.do

Thanks

Anil
 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try by removing .do in form action attribute
html:form action="/greeting"
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sai,

Tried your suggestion. It did not change anything. got the same issue.

Anil
 
sai prasanna
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the forward path attribute you try with pages/greeting.jsp or /pages/greeting.jsp
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil,
Replace your action mapping with this in struts-config.xml
<action path="/greeting" type="sample.GreetingAction" name="GetNameForm" scope="request" input="/pages/inputname.jsp" >
<forward name="sayHello" path="/pages/greeting.jsp"/>
</action>
The problem is the request is being passed to your GreetingAction Servlet.Your GreetingAction Servlet knows to dispatch
the request to "sayHello" to generate the response but it is not able to locate greeting.jsp since you had not mentioned the complete virtual path of greeting.jsp correctly.You have mentioned only (/greeting.jsp).
In the inputname.jsp your action tag should be like this
<html:action name="/greeting">
 
AnilPrakash Raju
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys,

I stuffed in up in the Action

Made some changes to the Action but forgot to take the complied classes from eclipse to the tomcat directory.

Thanks



Anil
 
Skool. Stay in. Smartness. Tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!