• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

using a href link to pass parameters to servlet.

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the syntax for using an href link to pass parameters to a servlet?
Example: <a href="/actionController?id=1&sid=2">Menu Option</a>

It works fine if I use: <a href="/actionController">Menu Option</a>


Thanks,
Dave
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind, it is ultimately the HTTP protocol that determines how parameters get past. As such, the same syntax is used for Servlets that is used for regular HTML pages.

So the syntax you listed is correct. When using a href link, the request method will be a GET and thus Servlet�s doGet() method is called (if the parameters are past as part of a from, and the form�s method is post, the doPost() method is called).

When using the link <a href="/actionController?id=1&sid=2">Menu Option</a> is your Servlet not working? If so, what is the problem or error message you are getting. In addition, can you post the code from your Servlet in which you are accessing the Parameters.

If this is a case where you did not create the Servlet, one thing to be aware of, it is not an uncommon practice (for security purposes) for a Servlet to allow parameters only to be received via a POST. Sometimes the Servlet may even be coded such that if any parameters are received via a GET, it does not simply ignore them and function as if none were received; it may display an error.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This post is old but have some valuable information.
If somebody visits it please let me know if we donot want to use href GET method property ,is there some way we can use POST method in href.
Reason for my question is I want to use href links only for a application where form cannot be used due to some resons.but as in href parameters being passed are displayed in URL as soon as they are clicked it is ,i donot want it to be displayed in URL.

If the above case doesn't works in any condition then do we have any alternative to this situation where POST method should be used without using form tag......

Regards,
Anisha
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try and emulate the HTML Form structure and submission through HTTPClient. This is to get you started.
 
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic