Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Help:Action forward to jsp directly in struts

Thread view: 
avrootshell - 19 Oct 2006 21:31 GMT
I have a Action class which takes care of business logic in struts.
Depending on some condition i'm thinking of forwarding the action
directly to jsp instead of giving path to action mapping.

I was trying to do something like this.

ActionForward af = new ActionForward();
af.setRedirect(true);
af.setPath("/jsp/some.jsp);
return af;

Bcoz i know i can do,[af.setPath = "../app/search");]
It means i can specify action mapping path here.

But this doesnt seem to be working .

One way to do would be like this:
return actionMapping.forward("success");
And in the action mapping in struts-config , i can forward it to jsp.

But i dont want to do this way. Bcoz there are so many conditions and i
dont want so many forwards in struts config .
Is there any way i can forward request to jsp directly?
Any kind of help is appreciated.
Manish Pandit - 19 Oct 2006 21:49 GMT
You can use the request dispatcher like this:

request.getRequestDispatcher("path to your jsp").forward(request,
respose);

Just make sure you do not commit your response before calling this
method.

-cheers,
Manish
avrootshell - 19 Oct 2006 22:08 GMT
Thanks for ur help Manish,

I need to return actionmapping.

so do you suggest, instead of

return mapping.forward("success");
just include

request.getRequestDispatcher("path to your
jsp").forward(request,respose);

I'm sorry , i'm new to struts . SO this type of questions may arise.
Manish Pandit - 19 Oct 2006 22:32 GMT
You're welcome - and its okay - Struts can be confusing at times.

You do not need to return an actionmapping. When you use request
dispatcher, the server will direct your request and response to the URL
you specify. The control is *never* going to come back to the execute()
method. For compilation's sake, you can do a return null. However, to
reiterate - make sure you do not commit your response before calling
the dispatcher - this will lead to an illegal state exception. Normally
I've used this API to process the request, set some request attributes
for the JSP being called and thats it. I never touched the response
throughout this process.

On another note, if you wish the control comes back to execute(), look
at the include() method of RequestDispatcher interface.

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.