This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Hi, I am trying to pass some parameters as a link to another page. Lets say I have two pages page1.jsp which contains a link to another page page2.jsp The link that I want to pass is this <a href="page2.jsp?niin1=123%&niin2=&itemName=test1223%" target="_self"> As you would have noticed, the link contains special characters, specifically '%'. Hence I encode it using the URLEncode.encode method from java.net lib. So, does one encode the complete link as in (1) URLEncode.encode("page2.jsp?niin1=123%&niin2=&itemName=test1223%") OR just (2) "page2.jsp?" + URLEncode(niin1=123%&niin2=&itemName=test1223%) OR (3) page2.jsp + URLEncode(?niin1=123%&niin2=&itemName=test1223%)
Anyway I tried all the 3 that I mentioned above. when I tried to do it by (1) and (3) the webserver said it could not find the page. when I tried the (2) request.getParameter gave me null as an answer. I am using Oracle containers for J2EE. I also tried it on my JDeveloper environment. I know I am missing something. But what ? All help greatly appreciated .. Thanx in advance...
Thanx frank for the quick reply... Just for the acadamic purposes, if I encode everything after the "?" that is the parameters names and the parameter values, and send them in the link, when page2 receives it, wouldn't the parameter names also be decode too, just like the parameter values are being decoded. So I could say request.getParameter("niin1") should return me a valid value instead of a null ?? Regards, Abraham
Joined: Jan 07, 1999
In that case the problem is because you are also encoding the "=" and "&". Without the "=", the servlet container doesn't know you have got any name=value parameters at all, and without the "&" it doesn't know where one parameter stops and another starts.
Joined: Oct 16, 2001
Thanx... I think I have it. It was infact very helpful..