• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do i use requestDispatcher.forward to forward to my struts action servlet?

 
Jacob Brozenick
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I currently have.
I'm receiving an xhr request from a jsp in a servlet i have mapped out in my web.xml. My servlet sends the data off to the back end for manipulation and returns the result to a registered callback handler in the browser for display.

What I need.
Based on conditions in the request I need the servlet to forward the request to a different jsp through a call to a struts action servlet.

It seemed fairly straight forward to me, this is what I have set up so far...

My jsp makes an xhr call to the servlet (with a flag telling it to forward to a different page)


My servlet then forwards the request to a struts configured action servlet


Through logging I can tell that my action servlet receives the request fine and then even forwards to the correct jsp


Through Firebug's "Net" tab I can actually see the request going out to "myServlet.do" then returning with the new jsp in the response. But nothing actually happens in my page it just sits there. I'm receiving no errors on the front or back and according to firebug i seem to be getting back what is expected, the browser just isn't doing what I expected it to do with the response.

I'm obviously missing something, any help and or constructive criticism on what I'm doing wrong or what I should do instead would be greatly appreciated.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you doing with the results of the request? This seems like a JavaScript issue.

It's confusing to name an action "whateverServlet.do", since it's not a servlet--it's an action. There *is* a Struts ActionServlet, which is the Struts controller.

Ditch the parenthesis around the return value :p

And do yourself a huge favor--use a JavaScript library to handle Ajax stuff.
 
Jacob Brozenick
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not gotten to how I will handle the results yet, most likely I will save them to a bean then access them in the jsp I forward to via taglib.

for now I'm just trying to get the forward to take me to the jsp. One solution that I know will work (but am trying to avoid) is to do an xhr call to perform the data crunching and save the results off to a bean, then upon return do a simple



I'm trying to avoid it because it seems messy and I was hoping I could take care of it all in one xhr call.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused.

You said the XHR response has the correct JSP in it--but if you don't *do* anything with that response, I'm not sure what you expect to have happen. Are you, perhaps, just confused about how Ajax works?
 
Jacob Brozenick
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the confusion I'm still a little green with this...

In my app i set up foo.do to call my struts fooAction.java, and can call that from the front with a link:


and my struts-config.xml is set up to forward that to foo.jsp when the fooAction.java returns with:


this takes my browse to the requested jsp.

but when I try to access foo.do from a regular servlet with a:


it does not take my browser to the jsp as I expected.

I am probably using Ajax a bit unconventionally here (or wrong even), im using it to POST the data to the servlet for manipulation then save the results in a bean. I was hoping to then forward the user to a different page via the requestDispatcher and not have to even worry about the return response to xhr, and now that I think about it thats probably exactly whats wrong...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole purpose of Ajax is to not move from the current page. So, yes, you're doing it wrong.

If you don't want to stay on the same page, don't use Ajax.
 
Jacob Brozenick
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ackk, I've been using nothing but ajax for so long, I forgot not to use it when I didn't need to.

sorry for the time waster... I realy wish my debut post here wasn't such a newbish debacle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic