I hope this helps someone else out there. I figured it out eventually.
When the .jsp file was in the home directory of my webserver (Mine was
c:\inetpub\wwwroot - I was using Personal web server) I had to use the path
to the file as follows:
INCORRECT
james = getServletContext().getRequestDispatcher("test.jsp");
=======================================path====^
CORRECT
james = getServletContext().getRequestDispatcher("/test.jsp");
---------------------------------------------------------------------------
----^
So I wound up using james =
getServletContext().getRequestDispatcher("/jsp/test.jsp");
That backslash made all the difference. I was using JRUN.
---------------------- Forwarded by Cassandra M. Sharpe/MCS/Price
Waterhouse on 11/17/99 04:31 PM ---------------------------
Cassandra M. Sharpe
11/17/99 01:15 PM
To: [EMAIL PROTECTED]@intl
cc:
Subject: Questions using Request Dispatcher and forward.
I have an HTML file that calls a servlet from a <form
action=".../servlet/actionservlet"> tag. My servlet queries a database and
retrieves a ResultSet object. My servlet uses the following code to make
the ResultSet available to a .jsp page for formatting. My goal is to have
the servlet perform the data processing and the .jsp do all the formatting.
I tried forwarding the request to a barebones .jsp page, just a HelloWorld
output and that wouldn't work either. I can call my test.jsp page directly
from the browser, but I can't get my servlet to forward information to it.
Code in servlet=====>
if (rs!= null) //rs is my ResultSet
{ request.setAttribute("resultset", rs);
//forward result to .jsp file
RequestDispatcher james;
james = getServletContext().getRequestDispatcher("../jsp/test.jsp");
james.forward(request, response);}
My test.jsp page is simple ====>
<%@ page import="java.sql.*" %>
<html>
<body>
<h1>My test Data forward - This line will always display<h1> <br>
<% try{
ResultSet rs;
rs = (ResultSet)request.getAttribute("resultset");
if (rs != null)
{ %> <table> <%
while (rs.next())
{ %> <tr><td> <%= rs.getString("title_name") %> </td></tr> <%
}
%> </table> <%} }
catch(SQLException e)
{ %> <tr><td>Database Error</td></tr> <% } %>
</body>
</html>
I cannot get this to work. I either get a blank page (I should at least
see "My Test Data Forward") or the status bar says "Connecting to site.."
and it just sits there as though it is trying to retrieve the page but
can't. I'm stuck. I am using Jrun and Miscrosoft Personal Web Server on
my desktop.
Thanks,
Cassandra
----------------------------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited. If you received
this in error, please contact the sender and delete the material from any
computer.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html