Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving values using option buttons.. please help!!

 
Sankar Bhamidi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just guessing at this point, but maybe "equalsIgnoreCase"???
 
Sankar Bhamidi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the same. you have to check conditionally.
Instead of declaring two methods , check these directyl
Binu
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic