This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Pass radio button to servlet

 
alona ariel
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?
 
Lorand Komaromi
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..?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64833
86
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
Pie
Posts: 64833
86
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".
 
Charles 'King
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:



 
swapnl patil
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.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • 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