Solved

Java basic web page not working

Posted on 2012-04-11
2
335 Views
Last Modified: 2012-06-21
I'm experienced using Classic ASP and ASP.NET but new to Eclipse and JSP.  Though very similar to Classic ASP I'm unable to get a basic example to work.  My code is a simple learning tool which is comprised of a class and method that returns a string array.  My webpage then iterates this returned object and loads a table's rows.  

The problem is that no values are ever recieved on the page.  The code always completes with empty rows.  What am I missing here?

//String array class
public class ResultLookup {

	//Class declarations

	//Class constructor
	public ResultLookup() throws SQLException, IOException
	{	
	}
	
	//Return a simulated dataset
	public String[] GetResultSet()
	{
		//Local declarations
		String[] strResultArray = new String[5];
		
		//Setup string array
		strResultArray[0] = "Sample text";
		strResultArray[1] = "A short placeholder";
		strResultArray[2] = "Slightly longer placholder";
		strResultArray[3] = "This code look just like Classic ASP";
		strResultArray[4] = "JSP the Hundia to ASP.NET's Honda";
		
		//Return result
		return strResultArray;
	}
	
}


//Web page to display my data
<table border="1">
		<tr>
			<td>
				Names
			</td>
		</tr>	
	<%
	
	try
	{
		ResultLookup objResultLookup = new ResultLookup();
		String[] strResults;
		strResults = objResultLookup.GetResultSet();

		for (int i = 0; i < strResults.length; i++)
		{
		%>
		<tr>
			<td>
			<% strResults[i].toString(); %>
			</td>
		</tr>
		<%
		}			
	}
	catch (Exception ex)
	{
		System.out.print("An TestResults.jsp error has occurred!");
		System.out.print(ex.getMessage());			
	}
	finally
	{			
	}
	%>
</table>

Open in new window

0
Comment
Question by:Phil5780
2 Comments
 
LVL 9

Accepted Solution

by:
ioanton earned 500 total points
ID: 37834387
Try replacing

<% strResults[i].toString(); %>

Open in new window


with

<%= strResults[i].toString() %>

Open in new window

0
 

Author Closing Comment

by:Phil5780
ID: 37835207
Great! This was my problem.  JSP feels just like Classic ASP scripted with C#.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JTable - RowFilter & Columns Header. 3 140
Stuck in Bootstrap WysiHtml Editor 3 37
rebasing and merging used in SCM 1 66
maven webservice example issue 2 122
Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
Note: This is the third blog post in a series on email clearinghouses (https://www.xmatters.com/alert-management/blog-email-has-failed-us?utm_campaign=70138000000ydLoAAI&utm_source=exex&utm_medium=article&utm_content=blog-post).   We’ve been talki…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now