File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
satya mamillapalli
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, but you have not done a good and clear job of expressing what you are trying to accomplish.
 
satya mamillapalli
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that the redirect need to be done on the client side when using Ajax, not on the server.
 
satya mamillapalli
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I repest -- do not do the redirect on the server.

Use Javascript to send the page to the next location.
 
satya mamillapalli
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless of whether you redirect on the client or the server all those things are true.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic