File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Pass radio button to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Pass radio button to servlet" Watch "Pass radio button to servlet" New topic
Author

Pass radio button to servlet

alona ariel
Ranch Hand

Joined: Sep 09, 2008
Posts: 36
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

Joined: Oct 08, 2009
Posts: 276
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..?


OCJP 6 (93%)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

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

Joined: Jul 05, 2009
Posts: 56

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

Joined: Aug 13, 2007
Posts: 80

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

Joined: Sep 09, 2008
Posts: 36
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

Joined: Aug 13, 2007
Posts: 80
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

Joined: Nov 06, 2000
Posts: 1506
As mentioned above, in case you did not notice, the value is not showing up because your checkbook is not checked.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pass radio button to servlet
 
Similar Threads
checkbox
405 error
doubt in getParameter()
getting null value from radio button
Reading Radio Button values