servlet request problem

Ok theres a site with an address similar to the following

http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID&cd=0

my servlet performs a check in the following way

//please note request.getString is the same as request.getParameter except it

//throws a certain exception if a string does not exist

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

if(view= confirm)

{

fileId= request.getString("id");

cd = request.getParameter("cd");

}

The problem is sometimes the address needs to be of this form

http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%26cd=0

So when this address is entered I get an exception that the string cd doesn't exist.

This is because of there being a "%26" instead of & before the "cd" end.

Is there anyway I could solve this problem?

[1130 byte] By [scorpion2a] at [2007-11-27 10:59:20]
# 1

%26 is the URLEncoded value of &.

Why needs the address to be of this form "sometimes"?

You could write a filter which decodes the URL and redirects to the decoded URL.

BalusCa at 2007-7-29 12:22:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I think I fixed the problem using decoder and substring and indexof.

What am I wondering about now is when the address is

http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%26cd=0

using URLDecoder.decode(file)

I get ID4793944974.ID&cd=0 so the %26 is converted to an &.

when the address is

http://test.address.uk/serverArea?view=confirm&file=ID4793944974.ID%2526cd=0

using decoder.decode(file)

I also get ID4793944974.ID&cd=0 for the file so %2526 also gets converted to an &.

Why are "%25" and "%2526" both decoded to "&"?

scorpion2a at 2007-7-29 12:22:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

[nobr]http://i-technica.com/whitestuff/urlencodechart.html

The %25 is the encoding for the '%' sign so %2526 means the %25 gets converted to '%' giving the %26

As an example the following jsp code:

<html>

<head>

</head>

<body>

Hello world <P>

<a href="urltest.jsp?x=Hello%2526world&y=Hello%26world">Link</a><P>

parameter x = <%= request.getParameter("x") %><br>

parameter y = <%= request.getParameter("y") %>

</body>

</html>

gives the following results:

Hello world

Link

parameter x = Hello%26world

parameter y = Hello&world[/nobr]

tolmanka at 2007-7-29 12:22:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...