Hi all,
I am trying to write a servlet that makes call to DB2 on mainframe and gets
the data to display. I have a JSWDK installed on my PC and web server
started. When I try to run the servlet, the Webserver crashes and I get an
error message that 'A network error has occurred while Netscape was
receiving the data'. There are no error messages in Java Console. The
Webserver console (DOS window) gets some SQL exception error message which I
am unable to see because the window shuts down too quickly and I am not
aware if the error message is captured somewhere else in a FILE. I am able
to run simple servlets without any problem. I am also able to run Java
application that can access DB2.
TIA
Sanjay Jain
8-226-7069
> -----Original Message-----
> From: Shelton, William D [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, July 28, 2000 9:15 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Servlet to Excel
>
> After you compile, IE requires you to specify a file extension in the
> request IF you want Excel to open in the browser. If you don't, the user
> will be prompted if they want to open the file or save the file, which
> will
> be named [ServletName] with no file extension. What I usually do is
> generate
> a quazi-random file name in the requesting page or servlet and append that
> to the query string of the calling page:
> <a href="servlet/ExcelForNorthwind?name=[text]&generatedFileName.xls">Get
> Excel</a>
>
> If you want the data to be submitted via method=post in a form, do this:
> <form action="servlet/ExcelForNorthwind/generatedFileName.xls">
> <!-- fields -->
> </form>
>
> NOTE: This should also work for Netscape, but I have not tested THIS code
> for Netscape yet.
>
> NOTE: This example works for Excel 97 & 2000. If you have users with Excel
> 95 or other spread sheet sw, you need to format the output NOT in an HTML
> table, but in a comma separated value format ( value1,value2,value3 + \n
> -- \n is the row delimiter). You can give the user the option prior to
> requesting the Servlet and conditionally process the output.
>
> All the best,
> --Bill
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.sql.*;
>
>
> public class ExcelForNorthwind extends HttpServlet {
> public void doPost(HttpServletRequest req, HttpServletResponse
> res)
> throws IOException, ServletException
> {
> doGet(req,res);
> }
> public void doGet(HttpServletRequest request, HttpServletResponse
> response)
> throws IOException, ServletException
> {
>
> // This is the main thing you have to do but
> // you also have to format output in an HTML table.
> // Alternatively you can delimit the query with commas and
> {CR}{LF}
> response.setContentType("application/ms-excel");
>
> PrintWriter out = response.getWriter();
> //We'll search by last name
> String name = request.getParameter("name");
> out.println( "You requested information on : <strong>" +
> name + "</strong>" );
> String tblStart = "<table width=550 border=1>";
> tblStart += "<tr bgcolor=\"#000000\"><th><font
> color=white>Last Name, First Name</font></th><th><font
> color=white>Title</font></th><th><font color=white>City,
> State</font></th></tr>";
> String tblEnd = "</table>";
> String bgColor;
> Cookie myCookie;
> String SQL = "SELECT * FROM Employees WHERE LastName Like
> \'%" + name + "%\'" ;
> int i = 1;
>
>
> try{
> Driver drv = (Driver)
> Class.forName("JData1_2.sql.$Driver").newInstance();
> Connection con =java.sql.DriverManager.getConnection(
> "jdbc:JDataConnect://localhost/Northwind::");
> PreparedStatement s = con.prepareStatement( SQL );
> ResultSet rs = s.executeQuery();
> out.println( tblStart );
>
> while( rs.next()){
> //Alternate row colors
> if( i % 2 == 0 ) {
> bgColor = "#ffffff";
> }
> else{
> bgColor = "#00cccc";
> }
>
> out.print( "<tr bgcolor=\"" + bgColor + "\">" );
> out.print( "<td>" + rs.getString("LastName") +
> ",
> " + rs.getString("FirstName") + "</td>");
> out.print( "<td>" + rs.getString("Title") +
> "</td>");
> out.print( "<td>" + rs.getString("City") + ", "
> +
> rs.getString("Region") + "</td>" );
> out.println( "</tr>" );
> i++;
> }
>
> out.println( tblEnd );
> s.close();
> con.close();
> }
> catch( Exception e ){
> out.println( "\n SQL Exception -- " +
> e.getMessage()
> );
> }
> }
> }
>
>
> //end
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ------------------------------
>
> Date: Tue, 27 Jun 2000 14:39:35 +0200
> From: Giovanni Santini SZ3PGQ <[EMAIL PROTECTED]>
> Subject: MS Excel
>
> Hello World,
>
> is there somebody who can give me an example of servlet to generate excel
> file?
> Thank you
>
> ------------------------------
>
> __________________________________________________________________________
> _
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
**********************************************************************
Please be aware that, notwithstanding the fact that the person sending
this communication has an address in Bear Stearns' e-mail system, this
person is not an employee, agent or representative of Bear Stearns.
Accordingly, this person has no power or authority to represent, make
any recommendation, solicitation, offer or statements or disclose
information on behalf of or in any way bind Bear Stearns or any of its
affiliates.
**********************************************************************
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html