• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need Help with check box values!

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 17698
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic