jsp:forward with right page name

Q

quickcur

I am writing a login page with jsp.

Here is my login.jsp:

<form action="verif.jsp" method="post">
username..password...
</form>

Here is my verif.jsp:

//if username and password are right
<jsp:forward page="home.jsp"/>

//else
<jsp:forward page="login.jsp/>

When the password is right and after home.jsp is shown, the address bar
in IE still shows "http://localhost:8080/myapp/verif.jsp". How can I
change that to "http://localhost:8080/myapp/home.jsp"?

Thanks,

qq
 
A

Alex Kizub

You don't need too.
Read more about MVC. and redesign your application.
It's home.jsp which should froward requset to ferify.jsp if login was not
correct.
Actually your entire application should have only one url - main.jsp or
home.jsp (or servlet if you wish)
And this home.jsp is C in MVC.

Alex Kizub.
P.S. Of course you can use redirection like this
<HEAD>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://localhost:8080/home.jsp">
</HEAD>
but this is very bad style for architecture and forbidden is only for
static web pages, not for jsp!
 
G

Ge Cong

Please answer questions not design issue. I have already considered the
design issue.
 
J

John C. Bollinger

Anyone know why?

Because a <jsp:forward> does not involve an additional HTTP round trip.
It all happens within The browser knows what page it requested, and
puts that in the address bar. It has no way to detect that the server
has provided a response from a resource with a distinct external name.
Contrast with the behavior when you perform an HTTP redirect (also
available to you) which sends a response to the client suggesting that
it make a new request for a different resource. In that case the
browser is fully aware of what's going on because it takes part.


John Bollinger
(e-mail address removed)
 
J

John C. Bollinger

So do we have other ways to do the login page?

The easiest are these:

(1) Put up with the wrong URL in the browser's address bar
(2) Use a redirect instead of a forward to send the authenticated user
to the ultimate destination

There are others of varying degrees of complexity.


John Bollinger
(e-mail address removed)
 
Q

quickcur

What is the difference between

response.sendRedirect("newpage.jsp") and

RequestDispatcher dispatcher =
request.getRequestDispatcher("newpage.jsp");
dispatcher.forward(request, response);

THanks,

qq
 
J

John C. Bollinger

What is the difference between

response.sendRedirect("newpage.jsp") and

RequestDispatcher dispatcher =
request.getRequestDispatcher("newpage.jsp");
dispatcher.forward(request, response);

Reread my first response in this thread.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top