Solved

Java basic web page not working

Posted on 2012-04-11
2
334 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
Comment Utility
Try replacing

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

Open in new window


with

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

Open in new window

0
 

Author Closing Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

12 Experts available now in Live!

Get 1:1 Help Now