This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Url hiding

 
d v lokesh venkata
Greenhorn
Posts: 16
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1725
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
d v lokesh venkata
Greenhorn
Posts: 16
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you suggest me any example like how to worrk with keeping jsp in web-inf and accessing it
 
J. Kevin Robbins
Bartender
Posts: 1725
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
 
J. Kevin Robbins
Bartender
Posts: 1725
19
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome. Glad I could help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic