• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Changing the URL when using forward or redirect...

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just wrote a long explanation of my problem, but I had placed a <jsp:forward in my subject line, and was told that <'s aren't allowed... so I backed up and everything was lost... I think someone should fix that.
Anyway, Here's my problem in a nutshell. I have a login.jsp and menu.jsp in my home folder, and everything else in a subdirectory. If a user tries to bypass the login screen by typing in a URL beyond home (home/reports/blah.jsp) I redirect them to the login page. The problem is that the URL the browser uses doesn't change... The login.jsp page will be displayed but the browser still things they're at 'home/reports/blah.jsp'... This messes up all my relative URL's.
After they login I try to send them to menu.jsp, but the browser tries to send them to home/reports/menu.jsp.
Is there a way to change the URL when forwarding or redirecting?
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think there is an easy way to change what appears in the browsers address bar. You'd have to do something dumb like calling a blank html page that redirects to your login page...messy.
To solve the relative page problem, I use all relative paths from the current context base directory. This way it should always work, regardless of whats in the broswers address bar (I could be wrong).
Hope this helps,
JEB
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use response.sendRedirect("/login.jsp") instead. Note that the bahaviour of this is fundamentally different to forward and include.
Forward and include work completelyy on the server side. The client asks for a page, you decide they should get another page and send them that instead. As far as the client knows, they got the page they asked for and hence the URL is unchanged.
sendRedirect is similar to the 'Jedi mind-trick'. The client asks for page A, you send a message telling them they want page B (this isn't the page you are looking for) and the client changes the URL then re-sends a request for the new page.
Dave.
 
Saloon Keeper
Posts: 28665
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that use of the [ CODE ] tags will protect any '<' - type stuff (such as sample HTML/XML). For quickie inline stuff, people often just put in a gratuitous space like so: < tag >. Notice I did that on "CODE" up above.
The reason for this is that otherwise the ubb sofware is likely to present your stuff as though it were html rather than passing it on unchanged.
You can also use the html/xml escapes: &lt; and so forth.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
by using
response.sendRedirect("xyz.jsp");
parameters are not getting passed from abc.jsp to xyz.jsp
i need parameters from abc.jsp in xyz.jsp
Bansal
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you put the parameters in the session
before you redirect? The page that accepts the
redirect could use session attributes if the
request parameters of interest were null.
HTH,
Joe
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hv three JSP pages
a.jsp, b.jsp, c.jsp
first a.jsp is loaded,
from a.jsp i move to b.jsp,
from b.jsp to c.jsp
and then c.jsp to a.jsp like this at any point user can come to main menu
when a.jsp is loaded and submitted I have to do some processing(data saving) and then forward to b.jsp
same on b.jsp first data saving and then move to c.jsp
same for c.jsp data saving and then move to a.jsp
when i move from a.jsp to b.jsp i need some parameters to be passed from a.jsp to b.jsp
and like wise from b.jsp to c.jsp
i dont need parameters from c.jsp to a.jsp
(but right now these r getting passed from c.jsp to a.jsp)

for this I m using forward action of JSP
<jsp:forward page="b.jsp" />
everything(data saving) is working good
but URL shown in address bar is not right
after first step it shows URL of 1 page past.
In action attribute of form I hv given the same JSP name
e.g. on a.jsp form action=a.jsp
after saving data I make a variable true
if variable is true(that means data is saved) I forward to next JSP
if data is not saved due to some error in isert statement it remains on the same JSP(and now URL changes to same page, means correct JSP page, as I m giving same JSP page in action attribute of form)
as for as functionality is concerned I think there is no problem I m getting what I want.
I have not fully tested.
i just tested on my standalone m/c.
i think functionality wise i shud not get any problem
but if URL shown is proper of the page which is displayed it will be more nice.
is there any other way around to get the same functionality and showing same URL.
I hope u got what I want to say......
hope for a better solution
Bansal
 
Sunil K Bansal
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hv not received any reply to my previous explanation,
that means there is no better solution.
or people just dont want to waste time on thinking, if above is funtioning without any problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic