# in url parameter

Hello! I have an url : http://.../one.jsp?a=ddd#aaa&b=nnnBecause of #, it fails, but I can't avoid it. ddd#aaa is a parameter that I get automatically and mast pass to the one.jsp. I can't change it. What can I do? Except of this parameter, I can change everything in this
[297 byte] By [nemariaa] at [2007-10-2 6:22:42]
# 1
Are you running your parameter names and values thru URLEncoder before you append them to the URL string?
bsampieria at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
You would encode the # as a %23 in the urlso in the address bar it would appear ddd%23aaaOf course it would be interpreted as a hash at the other end.
evnafetsa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
No, I can't change the value to %23, because it's passed automatically and not by me and contains #. But, except of this value, before and after it, I can change this url as i wish. What can I do?
nemariaa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
To bsampieri:How can I run the value through the URLEncoder? Can I append the URLEncoder to this string? Thanks.
nemariaa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Hi,you can use escape("QueryString") in URL.This will work if you forward the URL from java script Example: strString = URLwindow.open(escape(strString));Hope this will help you....Regards,ulzavan
ulzavana at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Unfortunately, I can't run the URL from javascript, I must run it from iexplore.exe directly. The command line is:iexplore.exe http://.../one.jsp?parameter1=...#...&parameter2=...Because of this # , it doesn't work.
nemariaa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
sigh...Take the url string.String urlString = ....String newURLString = urlString.replaceAll("#", "%23");use this "escaped" url string on your page:<a href="<%= newURLString %>>Click here </a>">
evnafetsa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

> sigh...

>

> Take the url string.

> String urlString = ....

> String newURLString = urlString.replaceAll("#",

> "%23");

>

> use this "escaped" url string on your page:

>

> <a href="<%= newURLString %>>Click here </a>

Seriously? Okay...

String urlString = "http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html#1.6";

Try clicking :

http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html#1.6

and

http://java.sun.com/j2se/1.4.2/docs/guide/util/logging/overview.html%231.6

and see where that gets you.

That is not the way you do it. You use java.net.URLEncoder.encode() on the name and value parts of the query-string part of the URL only. But not on the whole query string part because you don't want to encode the & and = separator chars.>

bsampieria at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
**** it! I knew there was a library somewhere that did this. I just couldn't for the life of me remember where.agreed, you only want to do this on the name/value parts of tHowever the OP seems to think that he can't for some reason.What is preventing it?
evnafetsa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10

People! Please! Maybe I didn't make myself clear.

I CAN'T encode this:

http://.../one.jsp?parameter1=aaa#bbb

because I get it from another program(it's like a black box for me), and the part of the URL after #, including # itself, is cut off, and I want it to recognize #bbb as a part of parameter1 and not to be cut off.

My code in one.jsp file is:

java.lang.String result1 = request.getParameter("parameter1").trim();

So, if parameter1=aaa#bbb, I get result1 =aaa, and the other part is cut off. And I want result1 to be aaa#bbb.

Any suggestions? Maybe, I should write in the code of one.jsp:

request.setSomething() (joke, any type of encoding),

so that it will recognize # as a part of the parameter?

nemariaa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

No, I don't believe there is anyway that you can tell it to ignore the # in the request string.

The # is defined in the http url address as having a special meaning.

You cannot override it.

The code calling your JSP/servlet is faulty for not escaping the # sign.

There is nothing you can do at the response end.

caveat: you MAY be able to do this in a servlet by reading the input stream directly, I am not sure. As the section after the # is not even required by the server, I am not certain if it would be transmitted or not.

Ok, I think I am understanding now.

Another program is making a request with this URL.

You don't have control over the request code, just the code reading the request.

Just to make sure

- how is this url being generated?

- how is the url being invoked? Someone clicking on a web page, or is a program doing it?

If you could explain things a bit like that - ie what programs/servers are involved, and how they are being generated/invoked then we might be able to help.

evnafetsa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

how is this url being generated?-

I generate it myself. Only the parameter (including #) is passed by another program.

how is the url being invoked? Someone clicking on a web page, or is a program doing it?

The program runs from the command line:

iexplore.exe http://.../one.jsp?parameter1=

and the other program passes the parameter to it.

Is there any other way to pass the parameter - not by attaching it to the URL? It must run from the command line. Something like

iexplore.exe http://.../one.jsp aaa#bbb?

And if so, how do I recieve it on my server side(jsp code)?

nemariaa at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13

Hi nemaria,

What do you mean the # is being generated by another program?

I would have a way how you could play a small trick on your pc, but I am afraid it would not be the most original.

basically instead of ivoking "iexplore.exe http://.../one.jsp?parameter1="

you will save a file on your the client drive. You then create a simple page and always load this page ... "iexplorer.exe mypage.html"

Here you use some javascript to load the file data. The following could do it I think

// Where layer is some elemtn on the screen.

document.layers[id].load(url,width);

And then you can change this character # with something else, still using javascript if you want. As I said not the best solution... it is still morning over here!! and so if anyone thinks this is bullsh*t, please say it so the OP does not have false hopes it could work!

regards,

sim085

sim085a at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14

hi,

Can keep saying that it must run from the command line, so are you doing this all via a batch file? If yes, then can you show us how you are recieving the parameters you are ment to be passing? I think this might help us to understand your problem somewhat better.

Have you considered moving all this into a small Java app? And then use the Runtime.getRuntime().exec("command") command to run your programs? If you can recieve the string (parameters) returned by your commands, then you can do all the encoding already suggested above...

HTH.

Eric

munyula at 2007-7-16 13:24:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15

Couple of things that are very clear -

1. You have to encode this request before sending it to the server. There's no way you can send # in the url and expect it to be delivered intact. evnafets had posted that the replacement ought to be '%23'.

2. your jsp is at the receiving end of this request - you cannot do any encoding here.

The way to do it would be to invoke the url in this fashion

http://....../something.jsp?param1=aaa%23bbb

And then in the jsp,

request.getParameter("param1")

would return aaa#bbb on the server side.

>how is this url being generated?-

>I generate it myself. Only the parameter (including #) is passed by another program.

and later

>It must run from the command line. Something like

When you say you generate it yourself, do you have a program that generates this url ? In which case you will have to parse the parameter passed by the other program and replace # with %23.

ram.

Madathil_Prasada at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16

To munyul:

Can keep saying that it must run from the command line, so are you doing this all via a batch file? If yes, then can you show us how you are recieving the parameters you are ment to be passing? I think this might help us to understand your problem somewhat better.

The Url 'iexplore.exe http://.../one.jsp?parameter1=' - is the value of the column PROCEDURE_NAME in the oracle table. I enter this value myself. The program that is written not by me goes to this table, takes this value and appends the argument to it. The argument is taken from the user interface on the client side and includes #. NO, I CAN'T ENCODE IT BEFORE THIS. The field PROCEDURE_NAME in the table is the name of ANY program WRITTEN BY ME that recieves this argument. I could write program in JAVA instead and put it on the client's computer, but I wanted to avoid this.

Have you considered moving all this into a small Java app? And then use the Runtime.getRuntime().exec("command") command to run your programs? If you can recieve the string (parameters) returned by your commands, then you can do all the encoding already suggested above...

I'm afraid I didn't understand this solution. And should I put this Java app on the client side?

nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 17

>The program that is written not by me goes to this table, takes this >value and appends the argument to it. The argument is taken from the >user interface on the client side and includes #.

As far as I know, there's no other way except to go into the client program (is it java?) and have an encoder running there that properly escapes it (because tomorrow the argument may contain some other similar special character) before submitting the request.

ram.

Madathil_Prasada at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 18
Alas, Ram, the client program is a binary code. I have no way to change it. And, please, don't suggest me decompiler:)
nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 19

Nemaria,

Ok, now things are slowly making a little more sense... Given your description, it would appear that your best solution would be to install a small Java app on all your client machines that parse and execute the String passed by this blackbox. Try something like this:

import java.net.URLEncode;

class myapp()

{

public static void main( String args[] )

{

String enc = URLEncoder.encode(args[0]);

Runtime.getRuntime().exec("'iexplore.exe http://.../one.jsp?parameter1="+enc);

}

}

And in your DB: PROCEDURE_NAME = "java myapp "

HTH.

munyula at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 20
Runtime.getRuntime().exec("iexplore.exe http://.../one.jsp?parameter1="+enc);minus the ' which was a cut and paste error :p
munyula at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 21
Thank you, munyul .I'll use your solution.Although i wanted to avoid to install programs on the client side, but, as far as I can see, it's the only way to do this.Best regards.
nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 22

ther'es plenty of ways, including doing some custom URL parsing to suit your needs...

take the full URL, split it at the ?, take the stuff after ? and split that into name/value pairs at the &'s and ='s and encode the name/value parts and put it all back together.

Don't say you can't do anything, you can always do something.

bsampieria at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 23

Hi, bsampieri!

Would you please give me an example how to take the full URL

'http://zlt02/MMFromCadops/l.jsp?n=aaa#bbb'?

Because, when I write in my one.jsp file

request.getRequestURL(),

it returns

'http://zlt02/MMFromCadops/l.jsp'

and when I write

request.getParameter("a") ,

it returns

'aaa'-

it's cut after #.

nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 24

Hi, bsampieri!

Would you please give me an example how to take the full URL

'http://zlt02/MMFromCadops/l.jsp?parameter1=aaa#bbb'?

Because, when I write in my one.jsp file

request.getRequestURL(),

it returns

'http://zlt02/MMFromCadops/l.jsp'

and when I write

request.getParameter("parameter1") ,

it returns

'aaa'-

it's cut after #.

nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 25

at what point are you talking about...

technically, if you are getting the value from the request object, then it's too late to do conversion. Conversion should be done on the URL before it's used in a web server request.

that being said, request.getQueryString() should return the raw query string.

bsampieria at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 26
Unfortunately, request.getQueryString() returns 'parameter1=aaa'and not 'parameter1=aaa#bbb'
nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 27

Yes... I know that. Which is why I said before that if you are doing this thru the request object in a servlet/jsp page, it is TOO LATE. You need to take care of those things BEFORE you submit a request.

If you're getting that request URL string only from the servlet side, then the caller of that servlet needs to create the URL it uses to call the servlet properly first.

At the point you are talking about in your last few post examples, there is NOTHING you can do.

bsampieria at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 28
Last try:)in the command "iexplore.exe http://.../one.jsp?parameter1=aaa#bbb"I can change EVERYTHING, EXCEPT OF aaa#bbb.Maybe there is some way to change this URL so that '#bbb' wouldn't be cut ?
nemariaa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 29
no.
evnafetsa at 2007-7-20 18:54:27 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...