File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Need Help with check box values! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Need Help with check box values!" Watch "Need Help with check box values!" New topic
Author

Need Help with check box values!

Sankar Bhamidi
Greenhorn

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

Joined: Mar 25, 2001
Posts: 33
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

Joined: Oct 09, 2001
Posts: 566
perhaps if we saw the JSP we could tell?


I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Sankar Bhamidi
Greenhorn

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

Joined: Feb 26, 2001
Posts: 5288
    
  10

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).]


Junilu - [How to Ask Questions] [How to Answer Questions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help with check box values!