Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: toString method not displaying properly in jsp


Message #1 by "davo jones" <optimation@h...> on Fri, 16 Mar 2001 18:56:00
I have a jsp file that accesses some classes which return a vector of Job 
objects. The Job object has a toString method that returns all of the 
variables. When using the class on its own, it returns the strings 
properly, but when i try to print out the Job object in a jsp e.g. 
out.println(job); it just prints: Job@6... 
It works fine when i am not using a jsp, but in a jsp i am getting a 
problem. I have attatched the code below, can anyone help?

Thanks.

<%@ page buffer="96kb" autoFlush="true" import="Job" 
errorPage="errorpage.jsp" %>

<jsp:useBean id="site" scope="session" class="SiteAnalyser" />


	<% 

	   site.setSearchString(request.getParameter("search"));
     String searchlevel = request.getParameter("level");



     int no = 0;
	   int sizecheck[] = new int[4];	  


     if(searchlevel.equals("1"))
        site.setSearchLevel(1);

     else if(searchlevel.equals("2"))
     {
        site.setSalaryString(request.getParameter("salary"));
        site.setLocationString(request.getParameter("location"));
 	      site.setSearchLevel(2);
     }

	   site.siteConnector();
     Vector results[] = site.getSearchData();

     Job jl = (Job)results[3].elementAt(0);

		out.println(jl.toString());


	   for(int count = 0; count < 4; count++)	
	   {
		    
		   sizecheck[count] = results[count].size();

		   if(sizecheck[0] < 1 && sizecheck[1] < 1 && sizecheck[2] 
< 1 && sizecheck[3] < 1)	
		   	 no = 1;	
				
     }
	 	 
      %>
 
<html>
<head>
<title>jobIT.com - Search results for '<%= request.getParameter("search") %
>'</title>
<style fprolloverstyle>A:hover {color: #FF0000; font-family: Arial; font-
size: 10pt; text-decoration: underline}
</style>
</head>

<body bgcolor="#808080" text="#FFFFFF" vlink="#3399FF" alink="#0099FF" 
link="#3399FF">

<div align="center">
  <table border="0" cellpadding="0" cellspacing="0" width="450" 
height="265">
    <tr>
      <td width="450" height="137">
        <p align="center"><img border="0" src="images/logo.jpg" 
width="450" height="135"></td>
    </tr>
    <center>
    <tr>
      <td width="100%" background="images/back.jpg" height="34">
        <p align="center"><font face="Arial" size="2"><a 
href="index.html">Home</a>
        | <a href="help.html">Help</a>
        | <a href="contact.html">Contact</a>   <a 
href="info.html"><br>
        </a><img border="0" src="images/line.jpg" width="450" 
height="2"></font></td>
    </tr>
    <tr>
      <td width="100%" background="images/back.jpg" height="94" 
valign="top" align="left">
        <p align="center"><font face="Arial" size="2">

	<%

  if(no == 1)
	{
		
	%>
	<font face="Arial" size="2">Sorry, no results for that search. Try 
again.<p>
	</font>
        <form method="POST" action="searchresults.jsp">
        
          <p align="center"><font size="2" face="Arial">Quick Search on 
Title
          (Enter skills, e.g. Java)</font><input type="text" name="search" 
size="20">
          <input type="hidden" value="1" name="level">
              <input type="submit" value="Go!" name="B1"></p>
        </form>
        <p align="center"><font face="Arial" size="2"><a 
href="advancedsearch.html">Advanced
        Search</a></font>
	<%
	}	

  if(no == 0)
	{

	%>

         Results from search for: <b>'<%= request.getParameter("search") %
>'</b>
         <p>
	<center>To have these results e-mailed to you,<br> 
	enter your e-mail address:
	<form method="POST" action="mailer.jsp">

	<input type="text" name="email" size="20">

        <%
		   		
	   int counter = 0;
	   int upperb = 0;
	   int sitetrue[] = new int[4];

	   for(int count0 = 0; count0 < 4; count0++)	
	   {
		      if(sizecheck[count0] > 0)
	        {
			        upperb++;
		        	sitetrue[count0] = count0;
          }
     }
	   	
      
	   for(int count1 = 0; count1 < upperb; count1++) 
	   {
		    for(int t = 0; t < results[sitetrue[count1]].size(); 
t++)
    		{
			    Job job = (Job)results[sitetrue
[count1]].elementAt(t);

	%>
		    	<input type="hidden" value="<%= job.toString() %>" 
name="<%= counter %>">
		
	<% 
		      counter++;

	    	}
	   }


	%> 

	<input type="hidden" value="<%=counter%>" name="number">	

   	 <input type="submit" value="Go!" name="B1"></p>
        </form>
	
	</center>
	 <p>

	  <%
     upperb = 0;
	   int sitetrue2[] = new int[4];

	   for(int count3 = 0; count3 < 4; count3++)
	   {
		      if(sizecheck[count3] > 0)
	        {
			        upperb++;
		        	sitetrue2[count3] = count3;
          }
     }


 		
       for(int count = 0; count < 4; count++)
      	{

	             for(int i = 0; i < results[sitetrue2[count]].size(); 
i++)
	             {
			          	Job j = (Job)results[sitetrue2
[count]].elementAt(i);

                 // if(j.title() != null)


                  //out.println(j.title());
		          		out.println(j.toString());


	   %>
		<P>

	   <%
			     // out.println(job.title() );

        	     }
        }
	  }
    
	   %>

	</font></td>
    </tr>
    </table>
  </center>
</div>

</body>

</html>

  Return to Index