Hi Hirdesh
Thanks.
It still does not work!
I tried both options i.e. MyServlet in c:\tomcat\jakarta-tomcat-3.2.3\webapps\root\web-inf\classes and Note.txt (the file I try to read in c:\tomcat\jakarta-tomcat-3.2.3\webapps\root\root. My URL was http://localhost:8080/servlet/MyServlet. I still get "Hello World null Helloyou," i.e. it just seems to ignore Note.txt.
I then also tried putting MyServlet in c:\tomcat\jakarta-tomcat-3.2.3\webapps\examples and Note.txt still as above i.e. in ROOT directory, same result. I then put Note.Txt in the examples directory. URL was http://localhost:8080/examples/servlet/MyServlet. Same result. I tried with your code, no change ; Your statement System.out.println("path is----) is ignored i.e. I do not get the path printed early on, but at the end of the program ("null" after Hello World as above) .
I am completely baffled as I have been on this for 8 days.
Ken
P.S. My program is shown below. Any suggestions would be most welcome. I will immediately respond.
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
{
res.setContentType("text/html");
String path =
getServletConfig().getServletContext().getRealPath("/Note.txt");
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
