wood burning stoves 2.0*
The moose likes JSP and the fly likes Url hiding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Url hiding" Watch "Url hiding" New topic
Author

Url hiding

d v lokesh venkata
Greenhorn

Joined: Aug 09, 2013
Posts: 16

My requirement is that when iam redirecting through pages my url is like hostname/index.jsp or hostname/sucess?id=22. ow my requirement is the values should be hidden and it should be replace with the title of that page.
like hostname/sucess-page
Thanks in advance
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 826
    
  13

What you want to do is make your requests to a servlet and let the servlet forward to the correct page. That way the URL will only show the name of the servlet and not the page. This is the correct way to build a JSP application, by the way. All requests should always go through a controlling servlet; never call a jsp page directly. In fact, I've recently started building all my apps with the jsps stored under the WEB-INF folder so they inaccessible except through a servlet.

One more thing, even when going to a servlet, if you are doing a GET, the parameters will still be visible in the URL. You can avoid that by always using POST, but you will get differing opinions on whether it's correct to use POST when you aren't posting data.

I'm curious why this is a requirement. If it's in the name of security by obscurity, it won't work. Anyone with Firebug or Fiddler will still be able to see all the information that you are trying to hide from the URL.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
d v lokesh venkata
Greenhorn

Joined: Aug 09, 2013
Posts: 16

Can you suggest me any example like how to worrk with keeping jsp in web-inf and accessing it
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 826
    
  13

When the servlet uses a RequestDispatcher it will be able to "see" the jsp page, but it cannot be accessed directly by URL.

Let's say you have a servlet called NewsHeadlines. Your URL will look like http://yourdomain.com/NewsHeadlines. The code for the servlet might look like this:


In this case the users URL in the browser will still just display "http://yourdomain.com/NewsHeadlines". The path to, and name of the page is completely hidden. But if the user tries to be clever and type the URL "http://yourdomain.com/WEB-INF/jsps/headlines.jsp" they will get an error because the browser cannot access anything under the WEB-INF folder. It's off limits to the browser. It only works when the servlet forwards the jsp (actually the generated html) to the browser.

d v lokesh venkata
Greenhorn

Joined: Aug 09, 2013
Posts: 16

Thank You
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 826
    
  13

You are welcome. Glad I could help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Url hiding
 
Similar Threads
The web server and the database in different computer
Login URL problem in my application
Actionforward url
Multilevel app structure
remmeber the URL design question