Encoding URL Query String .

Suppose my url is

<a href="http://1.1.1.1/aaa/aa.jsp?a=a&b=b&c=c" >

Now i dont want my url to look exactly like this but instead of these alpabets abc some special charaters should appear on the querry string in url .

If any body could help please .

Thanx in advance .

[320 byte] By [mohitagarwal] at [2007-9-26 1:24:41]
# 1
Try<a href="<%=java.net.URLEncoder.encode("your url here")%>">;
kblitz at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

thankx for ur reply .

but i am already using URlEncoder.encode() method . this only encodes special characters like space is converted into + sign . but if there is alphabet 'a' it passed as it is .

and i dont want to do that . i want that 'a' should appear something different in url so that user doesent know what all parameters i am passing in the url query string . kindly suggest something for this .

mohitagarwal at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Ah, now I think I understand what you want. You want to 'hide' or enocde the parameters that the user won't see them?

I think the closest to what you want is to use a form and use method="post".

<form method="post" action="yourlink">

<input type="hidden" name="a" value="xyz">

<input type="hidden" name="b" value="xyz">

...

<input type="submit" value="Go">

</form>

That way you won't see the passed parameters in the query string, but the user still could look at the HTML source to get the parameter names.

If the link is generated by your application and passed to the browser you also could encrypt/decrypt your parameters.

http://java.sun.com/products/jce/doc/guide/API_users_guide.html

kblitz at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
This is fine using post method and hidden form fields . but i am opening the new page with a link by a href so how is the encryption possible there .
mohitagarwal at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Is there anybody to help .
mohitagarwal at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
You can't
bjote at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Don't be silly, of course you can! You just need a little JavaScript.

Somewhere in your document header put a short script like this:<SCRIPT>

function doPost(val1,val2,val3,val4){

var f = document.formName;

f.FirstVal.value = val1;

f.SecVal.value = val2;

f.ThrdVal.value = val3;

f.FrthVal.value = val4;

f.submit();

}

</SCRIPT>

Your form will look something like this:<FORM NAME="formName" METHOD=POST ACTION="some.action">

<INPUT TYPE=HIDDEN NAME="FirstVal" VALUE="">

<INPUT TYPE=HIDDEN NAME="SecVal" VALUE="">

<INPUT TYPE=HIDDEN NAME="ThrdVal" VALUE="">

<INPUT TYPE=HIDDEN NAME="FrthVal" VALUE="">

</FORM>

And your links will look something like this:<A HREF="javascript:doPost(1,2,3,4);">Link1</A>

<A HREF="javascript:doPost(3,4,5,6);">Link2</A>

<A HREF="javascript:doPost(4,5,6,7);">Link3</A>

cafal at 2007-6-29 1:05:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...