Hi,
I'm trying to finalize a signup process for my webapp, but am getting confused with servlet forwarding/redirects (again). The flow looks like this:
// /signup/index.jsp
<form action='/user/signup'>
</form>
<%
if (request.getAttribute("msg") != null) {
%><div><%= request.getAttribute("msg") %><%
}
%>
// Servlet which maps to '/user/signup':
public void doPost(..) {
// process signup params..
// I want to show the user /signup/index.jsp again after completion:
req.setAttribute("msg", "signup worked!");
req.getRequestDispatcher("/signup/index.jsp").forward(req, resp);
}
when I use the forward() method, the browser shows the url of the post action still:
/user/signup
but the content is of:
/signup/index.jsp
this is what forward() is supposed to do. I am not sure if this is confusing to the user though - the url is different than the page that actually generated the content.
I stepped through what twitter does, looks like they are foward()ing the user around:
// twitter.com/signup
if (ok) {
forward("/find_sources/suggestions");
if (ok) {
forward("/find_sources/contacts");
if (ok) {
forward("/find_sources/anyone");
if (ok) {
forward("/");
}
}
}
else {
forward("/signup"); // error msg displayed here etc
}
In the above, if you mess up on the initial signup page, your browser shows the /account/create url, but the content of the page looks like /signup - so I guess they're doing the same thing I am (I am just assuming the underlying forward()/redirect() options are the same for all http servers, not specific to jsp).
Is my flow normal then? Should I be doing this some other way? I guess the options are:
- Use forward() and accept that the url will be of the action url.
- Use redirect() and store any messages I want to show the user in a session.
Thank you