Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

passing string with href..(URGENT)  RSS feed

 
barnali chakrabarty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sarath Mohan
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
My Suggestion is not to use tokens while sending string along with URL. Better to use Encoder and Decoder classes instead
Cheers
Bin
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Boss can u pls tell me what r the utilities does Encode and Decode classes provide.. bcoz i m facing problem to send data to a database from a textarea..
Pranit..
 
barnali chakrabarty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
barnali chakrabarty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you James for making the concept clear.However,your previous suggestion just worked fine and solved my problem.
Thank you again.
barnali
 
Jignesh Malavia
Author
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using single quotes within double. Should work just fine

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!