Hi Folks,
 
I had developed a servlet to read a file, using jsdk2.0. This was done mainly because of the help I got from this list especially Pierre Saumont(pys).
Now I have upgraded to tomcat and I tried using the same code to read the same file, but it does not work. It does not print anything i.e. when I access the servlet it gives me a blank screen, no error messages although it compiles well. The file in question is a text file. My servlet is stored in tomcat/jakarta-tomcat-3.2.3/webapps/root/web-inf/classes. The texxt file is in the same directory. When it did not work, I moved the text file to another directory i.e. tomcat/jakarta-tomcat-3.2.3/webapps/examples, since this made it similar to where it was stored (and worked) in JSDK; no luck. 
I give below the code I used:
 import java.io.*;
import java.util.Enumeration;
import java.awt.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.awt.event.*;
import javax.swing.*;
/**
* This is a simple example of an HTTP Servlet that
* uses the HttpSession
* class
*
* Note that in order to gaurentee that session
 *  response headers are
* set correctly, the session must be retrieved before
 * any output is
* sent to the client.
*/
public class MyServlet extends HttpServlet {

  JTextArea theTextArea   = new JTextArea(20, 64);
  JButton   theReadButton = new JButton("Read");
  String filename;
 
  public void doGet (HttpServletRequest req,
   HttpServletResponse res)
      throws ServletException, IOException
      {
                     String path = getServletConfig().getServletContext().getRealPath("./webapps/examples/Note.txt");
   System.out.println(path);
  StringBuffer sbuf = new StringBuffer();
  try {
  BufferedReader br = new BufferedReader (new FileReader(path));
  while(true)
  {
  String s = br.readLine();
  if (s == null)
  {
    break;
  }
   sbuf.append(s);
   sbuf.append("\n");
  }
 }
 catch (Exception e)  {
 }  
                 res.setContentType("text/html");
              // then write the data of the response
              PrintWriter out = res.getWriter();
                out.println("<html>");
            out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
    out.println("<BODY>");
    out.println("<BIG>Hello World</BIG>"); 
            out.println("<HEAD>");
   out.println(path);
              out.println("<title>the title of my document</title>");
                            out.println("</head>");
             out.println("HelloYou, ");
              out.println("<body>" + sbuf + "</body>");
                out.close();
 
  }
}


Get your FREE download of MSN Explorer at http://explorer.msn.com
___________________________________________________________________________ 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

Reply via email to