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

Need Help with check box values!

 
Sankar Bhamidi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Can someone help me? I have 4 checkboxes... and in the HTML they look like this:
<Input type ="Checkbox" name="jobType" value="FULLTIME">Fulltime
<Input type ="Checkbox" name="jobType" value="PARTTIME">Parttime
<Input type ="Checkbox" name="jobType" value="INTERN">Intern
But when I process it with the JSP page and want to enter the chosen value as text, it inserts something like this:
[Ljava.lang.String;@74bcf7
[Ljava.lang.String;@9fa8f
Can someone please help me, as to why the values of the checkboxes are not inserted??
Thanks!
CHARAN
 
Dmitriy Pavlyuk
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem is very strange. Symbols which you are get in the value is the memory link of your String object. Default when you output your string? the string value is outputing (method toString() is calling). May be you have another mistake in your code.
Try to call method toString() actually, f.e. <%=yourString.toString()%>, but it's equal to <%=yourString%> if "yourString" has a String type.
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
perhaps if we saw the JSP we could tell?
 
Sankar Bhamidi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your replies. Here is the relevant code in the java file and then the JSP page. Please help:
public class Student implements java.io.Serializable{
private String[] jobType;

public Student(){
jobType=new String[] { "1" };
}
public void setJobType(String[] jobType){
this.jobType=jobType;
}
public String[] getJobType(){
return jobType;
}
}
The relevant JSP code is :

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.io.*" %>

<jsp:useBean id="s" class="Student" scope="request"/>
<%String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url = "jdbc dbc:Resume";
String SSN;

Class.forName(driver);
Connection con=null;
try{
con=DriverManager.getConnection(url);

Statement stmt=con.createStatement();

String st= "insert into Profile values("+s.getSsn()+",'"+s.getLastName()+"','"+s.getFirstName()+"','"+s.getEmail()+"','"+s.getGender()+"','"+s.getDegree()+"','"+s.getMajor1()+"','"+s.getMajor2()+"','"+s.getGradua tionDate()+"','"+s.getAuthorization()+"','"+s.getJobType()+"','"+s.getGpa()+"','"+s.getSkills()+"')";
String st1= "insert into resume(Ssn) values("+s.getSsn()+")";
stmt.executeUpdate(st);
stmt.executeUpdate(st1);
SSN= s.getSsn();
stmt.close();
stmt=null;
}finally {

if(con!=null) {
con.close();
}
}
%>
<jsp:forward page="welcome.jsp"/>

Thank y'all!
CHARAN

 
Junilu Lacar
Bartender
Pie
Posts: 7465
50
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Herein lies your problem (see sections highlighted):

Originally posted by Sankar Bhamidi:
public class Student implements java.io.Serializable{
private String[] jobType;

...
public String[] getJobType(){
return jobType;
}
}
The relevant JSP code is :
...
String st= "insert into Profile values("+s.getSsn()+",'"+s.getLastName()+"','"+s.getFirstName()+"','"+s.getEmail()+"','"+s.getGender()+"','"+s.getDegree()+"','"+s.getMajor1()+"','"+s.getMajor2()+"','"+s.getGradua tionDate()+"','"+s.getAuthorization()+"','"+s.getJobType()+"','"+s.getGpa()+"','"+s.getSkills()+"')";

s.getJobType() returns a String[], not a String. Since concatenating strings will implicitly call the toString() methods for objects, Array.toString() will be called for a String[].
Suggested solution: Create another get method, say getJobTypeString(), that returns a String. This method will loop through this.jobType and build up the correct String you need.
------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform
@#$!)?/# UBB formatting!
[This message has been edited by JUNILU LACAR (edited November 09, 2001).]
[This message has been edited by JUNILU LACAR (edited November 09, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic