This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Can I use requestDispatcher.forward while using AJAX for Loading image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can I use requestDispatcher.forward while using AJAX for Loading image " Watch "Can I use requestDispatcher.forward while using AJAX for Loading image " New topic
Author

Can I use requestDispatcher.forward while using AJAX for Loading image

satya mamillapalli
Ranch Hand

Joined: Jun 22, 2005
Posts: 63
I was trying to use AJAX to call the servlet and forward it to a new JSP. I was doing this to create the loading image display animated but the page is not forwarded.

Can someone advise how to get the loading image animated when it goes from one JSP to the other JSP..

My problem is when I try to display loading image before the submit(without ajax) , It does not animate..After submission the image shows but does not animate..

But if I call thru Ajax, the loading image animate but I am not able to forward it to next JSP..

I know you are not supposed to use Ajax to move from the current JSP. BUT I woudl like to know how to get the loading image animated as it gets the data for the next JSP.
I would like to show animated display while request is being processed using AJAX.

JSP X (submit) ---> JSP Y

but the servlet takes time (lot od DB operations) to make request ready for JSP Y. I would like to display animated loading image on JSP X while the request is being processed


Please advise

Thanks
Satya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Sorry, but you have not done a good and clear job of expressing what you are trying to accomplish.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
satya mamillapalli
Ranch Hand

Joined: Jun 22, 2005
Posts: 63
Bear Bibeault wrote:Sorry, but you have not done a good and clear job of expressing what you are trying to accomplish.


Bear

May I ask you what you did not understand from my question..

Here is my requirement

JSP X (submit) ----- thru Servlet---> JSP Y

but the servlet takes time (lot of Database operations) to make request ready for JSP Y. I would like to display animated loading image on JSP X while the request is being processed..

If I use Ajax for the submit , the animated loading image works fine but I can not forward it to next JSP..

If I use form submit , the animated loading does not show animated,,

I would like to know how to show animated loading image on regular form submit..


Pleas let me know if you still not able to understand my requirement

Thanks
Satya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

satya mamillapalli wrote:... but I can not forward it to next JSP.

Why would you want to forward in this case anyways? A redirect is much more appropriate (See PRG Pattern). And it's easy to do a redirect once the Ajax request is complete.
satya mamillapalli
Ranch Hand

Joined: Jun 22, 2005
Posts: 63
Bear Bibeault wrote:
satya mamillapalli wrote:... but I can not forward it to next JSP.

Why would you want to forward in this case anyways? A redirect is much more appropriate (See PRG Pattern). And it's easy to do a redirect once the Ajax request is complete.


Bear

Thanks for your response.. I will try redirect and see if it works for me.

Thanks
Satya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Remember that the redirect need to be done on the client side when using Ajax, not on the server.
satya mamillapalli
Ranch Hand

Joined: Jun 22, 2005
Posts: 63
Bear Bibeault wrote:Remember that the redirect need to be done on the client side when using Ajax, not on the server.


Bear

I was not able to add the redirect in the callback method of my ajax call. All I have here is a javascript method.

response.sendRedirect(request.getContextPath() + "/next.jsp");
return;

Please advise

Thanks
Satya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

I repest -- do not do the redirect on the server.

Use Javascript to send the page to the next location.
satya mamillapalli
Ranch Hand

Joined: Jun 22, 2005
Posts: 63
Bear Bibeault wrote:I repest -- do not do the redirect on the server.

Use Javascript to send the page to the next location.


Bear

I have the follwoing issues with it if I do the javascript forward - window.location.href = next.jsp..

1. The URL is changing

2. Request values are not retained..

Is there a way I can do it like redirect on server..

Thanks
satya
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61105
    
  66

Regardless of whether you redirect on the client or the server all those things are true.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I use requestDispatcher.forward while using AJAX for Loading image