File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Retrieving values using option buttons.. please help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Retrieving values using option buttons.. please help!!" Watch "Retrieving values using option buttons.. please help!!" New topic

Retrieving values using option buttons.. please help!!

Sankar Bhamidi

Joined: Nov 05, 2001
Posts: 5
I am retrieving values from a database to a JSP page and I have option buttons for some of these values. But each time the page retrieves stuff, the option buttons are not showing the values, but showing the default options checked! The functions I'm using are isGenderSelected() and isAuthorizationSelected(). Could someone please point out what I'm doing wrong?
The following is the relevant code. Sorry, it's a bit lengthy!
Thank y'all!!!

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="*" %>
<%@ page session="true"%>
<%String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbcdbc:Resume";
String userId = (String)session.getAttribute("Ssn");
Connection con=null;



Statement stmt=con.createStatement();
String query="SELECT * FROM Profile WHERE Ssn="+userId;
ResultSet rs=stmt.executeQuery(query);
int ssn=rs.getInt(1);
String lastName=rs.getString(2);
String firstName=rs.getString(3);
String gender=rs.getString(4);
String authorization=rs.getString(5);
public String isGenderSelected(String s) {
return (gender.equals(s))? "checked" : "";
public String isAuthorizationSelected(String s) {
return (authorization.equals(s))? "checked" : "";
<input maxLength="9" name="ssn" size="9" value='<%=userId%>'> </td></tr>
<input name="lastName" size="20" value='<%=lastName%>'> </td></tr>
<input name="firstName" size="20" value='<%=firstName%>'>
<input CHECKED name="gender" type="radio" value="MALE" <%=s.isGenderSelected("MALE")%>>
<input name="gender" type="radio" value="FEMALE" <%=s.isGenderSelected("FEMALE")%>>
<input CHECKED name="authorization" type="radio" value="YES" <%=s.isAuthorizationSelected("YES")%>>
<input name="authorization" type="radio" value="NO" <%=s.isAuthorizationSelected("NO")%>>

Brian Glodde
Ranch Hand

Joined: Jun 27, 2001
Posts: 171
Just guessing at this point, but maybe "equalsIgnoreCase"???
Sankar Bhamidi

Joined: Nov 05, 2001
Posts: 5
Brian, thank you for the reply! But the same methods are working in another jsp page. The only difference is that, in that case, I'm calling the same methods from a class file, any ideas??
Thank you once again!!
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

you have to conditionally include the text "CHECKED" based on the value returned by the method.You appear to write it regardless.
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
I think the same. you have to check conditionally.
Instead of declaring two methods , check these directyl

Sarath Mohan
I agree. Here's the link:
subject: Retrieving values using option buttons.. please help!!
It's not a secret anymore!