• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

anchor tag and passing a variable

 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Someone told me last night that you can pass a value through an anchor tag. How exactly do you do this?
ex:

in the example, I was told that after the location, you can put a question mark followed by the variable name, and then the value. Do I have it right?
It's then going to a servlet doGet method.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have it right but you might want to lost some of the double quotes. Here is an example passing two variables to a servlet:
<a href="/MyApp/ControllerServlet?transaction='sometran'&action='someaction'"> bla bla bla </a>
Please note that the "&" represents a space. Also this method of passing data is referred to as using the querystring. You will notice that the data will also be displayed in the http address line.
Hope this helps,
Joe
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll have to clear this up, as both your examples still have problems.
To pass parameters in a GET request, put the parameters as name=value pairs after a '?', with each pair of parameters separated by '&'. There are some characters which must not appear in a URL (quotes, spaces, '>' etc.) so all non alphanumeric characters should really be 'URLescaped' as follows:
replace each space with '+' replace all other non-alphanumeric character with a '%' followed by the ASCII character code for the character as two hex digits.
For an example; to pass the follwoing parameters:
name = Peninsula and Orient
abbrev = P&O
to the script, servlet, JSP etc. at http://somwehere.com/show
we would build a URL like:
<a href='http://somwehere.com/show?name=Peninsula+and+Orient&abbrev=P%26O'>P&O</a>
Has this cleared things up?
[This message has been edited by Frank Carver (edited March 08, 2001).]
 
Joe Paolangeli
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for clearing things up. Yes '&' is used to seperate parameters and '+' is used to represent a space. I did not know about the '%'.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! I'll try it. I don't have to do anything different in terms of calling the servlet or anything, right? Just clicking on the link will do it?
What about at the servlet side?(another forum right?)
Can I say req.getParameter(name)?
'name' being the variable after the '?'
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ASP includes a built-in function to encode URL strings: Server.URLEncode(urlString). JSP doesn't have this function, but you could write one pretty easily if this is something you will be using more than once.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I'll only be using it once. As far as I know, anyway. Plus the page that it's coming from is generated by a servlet. So I just needed to know how to write out the line, with the appropriate characters and stuff. But thanks! That would have been another option! (and still might be if I will need to use it more!)
Annette
 
The only cure for that is hours of television radiation. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic