This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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
Joined: Aug 14, 2009
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.
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?
Joined: Aug 14, 2009
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...