Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Accessing JSP from HTML page

843840Jun 28 2008 — edited Jun 29 2008
Hi, I have been programing in Java for a while but I am brand new to HTML and JSP. I recently read a tutorial on how to create a Tomcat server (version 5.5) inside of Eclipse (version 3.3) and have it running a web server.

Everything is running great! I have an index.html and a index.jsp. The reason for the index.jsp was so that I could access the web site from http://localhost8080/WebProject/ (the index.html) or by going to http://localhost:8080/WebProject/WebContent/ to display the table of thumbnails that the jsp is supposed to provide.

Basically, I want to be able to open up the index.html and make a call to the jsp to have it populate, on the HTML page, the table. I would also like the ability to go straight to the table (as mentioned above).

The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>What's a title?</title>
</head>
<body>
	<h2>What?</h2>
	<br/>
	<table boarder="5" align="CENTER">
		<tr>
			<td>
				<a href="index.jsp?foo">Table</a> 
			</td>
		</tr>
	</table>
</body>
</html>
{code}and the JSP
{code:java}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.io.File"%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Title *******!!!</title>
</head>

<body>
<table WIDTH="360" ALIGN="CENTER" BORDER="1">
	<tr>
<%
	String directory = "\\workspace\\WebProject\\WebContent\\images\\";
	File dataDir = new File(directory);
	File[] listing = dataDir.listFiles();
	String filename = "";

	for(int i = 0; i < listing.length; i++)
	{
		if(i%8 == 0) {
			out.println("</tr><tr>");
		}
		filename = listing.getName();
%>
<td align="center">
<%
out.println(" <a href=\"images/"+ filename +"\"><img src=\"images/"+ filename +" \"" +
"width=\"90\" height=\"90\" /></a>");
%>
</td><%
}
%>

</tr>
</table>
</body>
</html>
I have read: 

 [JSP Tutorial|http://www.jsptut.com] 
 [Java Sun Tutorial|http://java.sun.com/products/jsp/docs.html] 

And a few others, and I am just not seeing information on what I am trying to accomplish.  I read that you should not develop your entire page as a JSP page and that you should use JSPs to access data and perform operations such as the one I am attempting.  Am I completely misunderstanding what JSPs are used for and how to use them? 

I do know that the href is obviously wrong and that it is bringing up a new web page, but is there a way to just have the page (script) run inside of the table slot on the main html page?

Edited by: amischiefr on Jun 28, 2008 1:47 PM

Edited by: amischiefr on Jun 28, 2008 1:48 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 27 2008
Added on Jun 28 2008
4 comments
367 views