File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Redirecting in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirecting in servlets" Watch "Redirecting in servlets" New topic

Redirecting in servlets

zel hatake

Joined: Feb 29, 2012
Posts: 1
Hi guys, I'm having problems with my redirection code for a java servlet code.

When a user clicks the Register button...
>the /regisration_page servlet will be shown wherein it have requestDispatchers composed of 3 fragments (banner.jsp,footer.jsp,content.jsp)
>the content.jsp contains the <form action="/register" method="POST"> when the user finishes filling up the necessary information, the servlet /register will then insert the data into the database.. well it work fine..
>but then i need to redirect the user to a page that will notify him if the registration is successful.

I tried the following...

In the /register servlet I inserted the ff in the doPost:

and I created a new fragment named registrationStatus.jsp that will get the parameter

And then how will I show the page to my user?
I thought of using the processRequest in the /register servlet wherein I used the RequestDispatcher to combine 3 jsp fragments and send it back to the client:

And its not working... I don't know what I did wrong.. is there something wrong with my logic???
Help will be much greatly appreciated. Thank you!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Sorry, but I cannot get past this:
You realize that this will completely mask any exceptions that are thrown?

[Asking smart questions] [About Bear] [Books by Bear]
Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 662

Java exception messages are written in a way, so that it will be easy to debug the problem and by having a empty catch block, you are not helping yourselves and is a very poor thing to do.
I agree. Here's the link:
subject: Redirecting in servlets
It's not a secret anymore!