Win a copy of Fixing your Scrum this week in the Agile 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Pass radio button to servlet

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..?
 
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67579
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'm still in control here. LOOK at this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic