Hi James:
You can generate JavaScript code in your servlet to display the caught
Exception. You can either display it in a new browser window or in an alert
box. I like the alert box better, because it can hold a good amount of data
and it very easy to maintain. The only problem, is that it will not scroll
if the data overflows.
All the best,
bill
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~
/* Servlet that generates the error and passes it to a new browser Window
*/
/* It also passes the same message to a JavaScript alert Box, which can
hold
a lot of data and is easier to maintain that another servlet ..
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ErrorMessage extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
PrintWriter out = response.getWriter();
response.setContentType("text/html");
try{
// Bad Code not caught at compile time ...
String SQL = "SELECT * FROM TableFoo";
Driver drv = (Driver)
Class.forName("JData1_2.sql.$Driver").newInstance();
// Generate a Bad DS Error ...
Connection con =java.sql.DriverManager.getConnection(
"jdbc:JDataConnect://localhost/BadDS::");
PreparedStatement s = con.prepareStatement( SQL );
ResultSet rs = s.executeQuery();
}
catch( Exception e ){
//out.println( "\n SQL Exception -- " +
e.getMessage() );
// Instead of the above, try something like this.
out.println( "<script>" );
out.println( "var message = '" + e.getMessage() +
"'" );
out.println( "var page =
'/dev/servlet/DisplayErrorMessage?error=';" );
out.println( "var myWindow = window.open( page +
message,'Popup', " );
//Set the optional properties to 1 to display them
...
out.println(
"'width=400,height=300,scrollbars=1,resizable=1,status=0,'+ " );
out.println(
"'menubar=0,toolbar=0,location=0,directories=0,copyhistory=0'); " );
//Let's also put the same message to an alert box
.... Much easier!!!
out.println( "alert(message);" );
//Make sure the new window is on top ...
out.println( "myWindow.focus();" );
out.println( "</script>" );
out.println( "See pop-up window or alert box for
error details ..." );
}
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException
{
doGet( request , response);
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/* This is the sevrlet that displays the error message ... */
import javax.servlet.*;
import javax.servlet.http.*;
public class DisplayErrorMessage extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.println( "<h3>An Error occured while processing this
request.</h3>" );
out.println( "Error Message: " +
request.getParameter("error") );
}
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException
{
doGet( request , response);
}
}
//end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----Original Message-----
From: James A. Rome [mailto:[EMAIL PROTECTED]]
Sent: Saturday, August 12, 2000 8:48 AM
To: JRun-Talk
Subject: Opening a second window
Is there a way to open a second browser window from inside a servlet? It
would be really useful if I could direct debug information there rather
than to the main window that is intercepted by the servlet.
--
James A. Rome
Lockheed Martin Energy Systems
Center for Information Infrastructure Technology
E-mail: [EMAIL PROTECTED]
URL: http://www.y12.doe.gov/~jar
----------------------------------------------------------------------------
--
Archives: http://www.egroups.com/group/jrun-interest/
Unsubscribe:
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/jrun_talk
or send a message to [EMAIL PROTECTED] with 'unsubscribe'
in the body.
------------------------------------------------------------------------------
Archives: http://www.egroups.com/group/jrun-interest/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/jrun_talk
or send a message to [EMAIL PROTECTED] with 'unsubscribe' in the
body.