wood burning stoves 2.0*
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
Author

Retrieving values using option buttons.. please help!!

Sankar Bhamidi
Greenhorn

Joined: Nov 05, 2001
Posts: 5
Hi,
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!!!

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

try{

con=DriverManager.getConnection(url);

Statement stmt=con.createStatement();
String query="SELECT * FROM Profile WHERE Ssn="+userId;
ResultSet rs=stmt.executeQuery(query);
while(rs.next()){
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" : "";
}
%>
<table>
<tr><td>
<input maxLength="9" name="ssn" size="9" value='<%=userId%>'> </td></tr>
<tr><td>
<input name="lastName" size="20" value='<%=lastName%>'> </td></tr>
<tr><td>
<input name="firstName" size="20" value='<%=firstName%>'>
</td></tr>
<tr><td>
<input CHECKED name="gender" type="radio" value="MALE" <%=s.isGenderSelected("MALE")%>>
</td></tr>
<tr><td>
<input name="gender" type="radio" value="FEMALE" <%=s.isGenderSelected("FEMALE")%>>
</td></tr>
<tr><td>
<input CHECKED name="authorization" type="radio" value="YES" <%=s.isAuthorizationSelected("YES")%>>
<input name="authorization" type="radio" value="NO" <%=s.isAuthorizationSelected("NO")%>>
</td></tr>
</table>
<%
}
rs.close();
rs=null;
stmt.close();
stmt=null;
}
finally{
if(con!=null){
con.close();}
}
%>
</BODY>
</HTML>

Brian Glodde
Ranch Hand

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

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
Rancher

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.
Dave.
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
Binu


Sarath Mohan
 
Don't get me started about those stupid light bulbs.
 
subject: Retrieving values using option buttons.. please help!!