Hi: I want to pass a string say "the blue fox" to a jsp page by href. i am using the code <a href="abc.jsp?var=a blue fox">link</a> but it is not working properly...ie. only "the" is being passed t the page. Can anybody help please? this is urgent... Also note that the href is directed to the same page from where it is called . ie., abc.jsp, so as to pass the variable in the same page and perform some task.Is it feasible? Thanks in advance.
You should use java.net.URLEncoder to encode the String, alternatively %20 is a space character in HTTP, or + seems to work so you could do: <a href="abc.jsp?var=a%20blue%20fox">link</a> or <a href="abc.jsp?var=a+blue+fox">link</a> Or you could use some other token and String tokenize it out yourself later.
Dear James, Thank you for your answer.Let's see if it works. But one thing is not clear does some specific class needs to be added for this functionality to work? Do i have to add this so called "java.net.URLEncoder"? is this a class. I shall be very glad if you put some more light on this. Thanks again for answering. barnali. Dear Binu, Thanks for your suggestion, but could you please put some more light on this encoder and decoder classes and how to use them in this pretext (if possible, with a code)? barnali.
java.net.URLEncoder is a utility class (I think it comes in the j2sdkee, but Im not certain). Take a look at the javadoc: <pre> public class URLEncoder extends Object The class contains a utility method for converting a String into a MIME format called "x-www-form-urlencoded" format. To convert a String, each character is examined in turn: The ASCII characters 'a' through 'z', 'A' through 'Z', '0' through '9', and ".", "-", "*", "_" remain the same. The space character ' ' is converted into a plus sign '+'. All other characters are converted into the 3-character string "%xy", where xy is the two-digit hexadecimal representation of the lower 8-bits of the character. Since: JDK1.0 </pre> You simpy use the static encode method: String myEncodedString = java.net.URLEncoder.encode("put your String here"); on the other end you use the decoder (just the same) to remove all the encoding stuff and give you original String back.