Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Pass radio button to servlet  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used radio button

<input type="radio" name="kaspomat" value="a10" >
radio button 2


<input type="radio" name="kaspomat" value="a20" >
radio button 3


<input type="submit" value="submit" >


Now I want to reaad my choise from a servlet ( to read a10) how can I pass these parameters to servlet and read them
I try in this way

String check = request.getParameter("kaspomat");

but it does not work

please someone can help me?
 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

alona ariel wrote:String check = request.getParameter("kaspomat");

but it does not work



Are the radio buttons in the same form and is the ation property of the form set to your servlet? What do you mean by "does not work", do you get some error message, or getParameter() returns null..?
 
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66797
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is one of the radio buttons checked?

And yes, please read this for more information on the uselessness of the phrase "it doesn't work".
 
Ranch Hand
Posts: 56
Eclipse IDE Postgres Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

alona ariel wrote:I used radio button

<input type="radio" name="kaspomat" value="a10" >
radio button 2


<input type="radio" name="kaspomat" value="a20" >
radio button 3


<input type="submit" value="submit" >


Now I want to reaad my choise from a servlet ( to read a10) how can I pass these parameters to servlet and read them
I try in this way

String check = request.getParameter("kaspomat");

but it does not work

please someone can help me?



What does your URL look like once you submit? Does it include your parameter, e.g. ("url?kaspomat=a10"). Here's example code for submitting a simple radio parameter:



 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

try this this will work

public class Radio extends HttpServlet{


public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
PrintWriter out = response.getWriter();
String args[] = request.getParameterValues("kaspomat");

for(int i=0;i<args.length;i++) {
out.print(args[i]);
}

}


}>
 
alona ariel
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i try to write the code as you recommended to me.
but still it does not work
it write to me

HTTP Status 405 - HTTP method GET is not supported by this URL

why this happened?
 
swapnl patil
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check your method name in form tag

in your JSP method name may be Post like <FORM ACTION="doSomething.jsp" method="Post">

its best practice to provide the implementation for post method also.

try this code




my jsp code



let me know if you have any quires.
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As mentioned above, in case you did not notice, the value is not showing up because your checkbook is not checked.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!