File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes hiding URL address with a fake one Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "hiding URL address with a fake one" Watch "hiding URL address with a fake one" New topic

hiding URL address with a fake one

Cathy Cruise

Joined: Jun 13, 2004
Posts: 25

I am currently using Servlet and Jsp to do a webpage. I would like to know, is there anyway to hide the URL address with a fake one? I know someone was able to did that. I was reading his code, and I couldn't find the trick. Does anyone know?

Thanx in advance
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

One way to do this is to submit to the "fake" URL. That URL maps to a servlet which forwards you to the real servlet/JSP.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Shankar Narayana
Ranch Hand

Joined: Jan 08, 2003
Posts: 134
Ex: web.xml

in your jsp your action would be like

Maintain a constant variable with the hidden field and check that in the servlet, corresspondingly redirect to the jsp.

"Failure is not when you fall down; its only when you fail to get up again."
Cathy Cruise

Joined: Jun 13, 2004
Posts: 25
hum... is there any other way beside this?

Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Cathy,

If you're just after hiding the URL in the address bar then you can always wrap your page in a FRAME, but this is nasty, nasty, nasty! It also only hides the URL from the non-technical user.

Ashish Agrawal
Ranch Hand

Joined: Nov 02, 2003
Posts: 112
You can use Front Controller Pattern, i.e. all your request go to a common servlet with your desired URL pattern. Depending upon the value of some of your form parameter you can decide what response to send.

Also you can use iframe html tag inside your html response. It doesnt display the url address in the brower.

- Ashish Agrawal
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
sounds awfully much like "I have this browser hijack I want to make to redirect people to my phishing scam without them noticing they're not really visiting eBay/Paypal/their bank".

Tina Desai
Ranch Hand

Joined: Mar 13, 2003
Posts: 365
I felt the requirement is like - keeping in the adress bar all the time. Not to deny that someone is at

Is it?


Alongwith being a good coder, try to be a good professional as well!
James West

Joined: Aug 13, 2004
Posts: 1

Shankar is correct.

In the below, replace "<" with a less than symbol, and ">" with a greater than symbol, and in "on Click" remove the space.

If you are confused, let me try to explain. After you have created your servlet and the web.xml mapping:

You can either set the action in the hidden field directly, or set it in a javascript.
Using javascipt allows many different actions easily.

"<"input name='action' type='hidden' value='action1'">"
"<"input name='action' type='hidden' value=''">"

"<"input type="button" name="myButton" value="Button 1" on Click="javascript:submitForm( 'action1' );"">"
"<"input type="button" name="myButton2" value="Button 2" on Click="javascript:submitForm( 'action2' );"">"
"<"input type="button" name="myButton3" value="Button 3" on Click="javascript:submitForm( 'action3' );"">"
"<"input type="button" name="myButton4" value="Button 4" on Click="javascript:submitForm( 'action4' );"">"

function submitForm( action )
document.forms[0].action.value = action;

on the form, you simply do a post:
"<"form name='myForm' method='POST' action='[SERVLET_URL]'">"

Your servlet should act as a traffic cop and pass on the request. You can find the action easily in your java code:

String action = (String) request.getParameter( "action" );

In the above examples, the value of the String 'action' will either be "action1", "action2", "action3", or "action4".

There are many other variations, but hopefully this is a simple and straight-forward option.

- James
Cathy Cruise

Joined: Jun 13, 2004
Posts: 25
oh yes.. i think this will be easier for me to do. Thank you very much to all of you.. ^_^

I agree. Here's the link:
subject: hiding URL address with a fake one
It's not a secret anymore!