Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying a loading page betwen 2 pages

 
thongvan alexis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

here is my problem,

1/a user submit some data
2/data is send to an application server wich will store the result in a database
3/user is redirected to a waiting page
4/user is redirected to a page wich display the result once the data is ready

problem is, once I send my User to the waiting page, I'm stuck, since the servlet forwarded to it, it won't do anything anymore.

the servlet wich does not work (get stuck once the loading page is displayed)



Any ideas?
Thanks
 
jatan bhavsar
Ranch Hand
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Have you Debug the application ? Are you able to reach inside the if condition..? You can print the logger or debug the application and see where you stuck? Any Exception in background.

Regards
Jatan
 
thongvan alexis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when entering the servlet the first timz next = false, so I'm not suposed to go inside the if.

when executing the line : getServletContext().getRequestDispatcher("/loading.html?next=true&key="+key).forward(req, resp);
Its just displaying loading.html, with the parameter from the servlet I was comming from (?next=false&key=xxx)

Basically it's not re-entering the servlet.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have a redirect in a loop?

Once you redirect of forward, that's it. You can do nothing else.

Maybe you need to back up 10 steps or so and tell us what you are actually trying to accomplish.
 
thongvan alexis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You have a redirect in a loop?

the redirect is in a conditional block, so it's not really a problem



Once you redirect of forward, that's it. You can do nothing else.


yes, and i'm looking for a workaround or an other way of getting the same result.


Maybe you need to back up 10 steps or so and tell us what you are actually trying to accomplish.


this

1/a user submit some data
2/data is send to an application server wich will store the result in a database
3/user is redirected to a waiting page
4/user is redirected to a page wich display the result once the data is ready
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you intend for the waiting page to know when the processing, which I assume is executing in a worker thread, is complete?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, perhaps I'm reading too much into this. From your list, it seems as if the "waiting page" may be completely superfluous. If the servlet stores the data in the database, what's the purpose of the "waiting page"? What's it "waiting" for?
 
thongvan alexis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's waiting for the data to be stored in the database.

You cannot know how much tim the calculation will take before database storage, could be 2 seconds, could be 15 seconds.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it were me, I likely wouldn't bother for such a short duration. But if you want to show a "waiting" notice while a request is processing, you're going about it the wrong way. You can't redirect or forward from the servlet until it's done, so the idea of showing a waiting page while the servlet is still processing isn't viable. You could go the thread route, but that's wildly overkill for this.

What I'd do is to submit the request as an Ajax call, display a waiting notice while it's processing, and simply remove the notice when the request completes.
 
thongvan alexis
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allright, impossible to do with only jsp/servlets.
I'll have to learn javascript/ajax then, thanks
 
Junilu Lacar
Bartender
Posts: 7466
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thongvan alexis wrote:I'll have to learn javascript/ajax then, thanks

Javascript libraries like JQuery make this really easy. You can get it done within an hour of Googling, coding, and testing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic