• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting url not working as expected

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am trying to store the url visited so when the session does not exist it redirects you to the login page then after login it will direct you to the page you were attempting to access.

Setup:
web.xml directs /action to servlet action.java

I access the page from the servlet(action.java) and redirect you to the jsp page via: request.getRequestDispatcher("/view.jsp").forward(request, response);
The url says the servelts name

So on the page action the url is:
localhost:8080/App/action

but request.getRequestURI().toString(); shows /App/view.jsp


How can I get the url to show the servlet address?


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A forward happens only on the server, so the browser knows nothing about it.

If you want the browser to fetch the new page, use a redirect, not a forward.
 
Kyle Bradley
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are saying seems backwards then... I want the url of the servlet which would not be the forwarded url.
 
Kyle Bradley
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
maybe I didnt explain it well enough...


If I do this I get the result I want:



Result gives me the url I want
Localhost:8080/App/action?whateverParametersIHaveHere


What I did not want to have to do was the check (parentPage.equals("/App/view.jsp"))

Is there not a way to get the actually url in the url bar? I thought that request.getRequestURL would give it to you but it is returning the forwarded url of the .jsp (I do not want the .jsp but the servlet address that is in the url bar)

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure why you would think that.

In any case, if I recall correctly, the container places attributes in the request that contain the original url information. If you carefully inspect the attributes (or look it up in the Servlet specification) you will likely find what you seek.
 
Greenhorn
Posts: 8
1
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't the container already handle all of this for you? If a page that requires a login is accessed, the request will be intercepted and redirected to the login page, and then redirected back to the original URL after logging in. This assumes that the standard and well-tested container-based security is being used, and you aren't trying to create your own login system for some reason.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Christian Taylor wrote:This assumes that the standard and well-tested container-based security is being used ...


Facts not in evidence.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get the context path and then point the servlet path according to url pattern of it.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic