If you are not getting the path printed out, you are not running the latest version of your servlet. I'd suggest recompiling it and running it again and putting print statements in until you are sure you are running the correct version of your code.
The first url http://localhost:8080/servlet/MyServlet is wrong. You need to specify which webapp you are running. In this case, you have a webapp called 'root' . I think you misunderstood some previous directions and confused the root directory of the webapp with an actual directory called root. Regards, Richard At 06:15 PM 10/13/01 -0400, you wrote: >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>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>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(); > > } >} > >From: Hirdesh Mishra > >Reply-To: "A mailing list for discussion about Sun Microsystem's Java > Servlet API Technology." > >To: [EMAIL PROTECTED] > >Subject: Re: servlet to read a file > >Date: Wed, 10 Oct 2001 09:21:46 +0530 > > > >http://localhost:8080/examples/servlet/MyServlet is what I used. > > > >and my path is D:\Tomcat\jakarta-tomcat-3.2.3\webapps\examples\Note.txt > > > >Thanks, > >Hirdesh Mishra > > > >-----Original Message----- > >From: A mailing list for discussion about Sun Microsystem's Java Servlet > API > >Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of ken dias > >Sent: Wednesday, October 10, 2001 5:36 AM > >To: [EMAIL PROTECTED] > >Subject: Re: servlet to read a file > > > > > >Hirdesh, > > > >I am using Windows ME. My URL Browser is localhost:8080/servlet/MyServlet. > > > >Thanks > > > >Ken > > > > > > >From: Hirdesh Mishra > > >Reply-To: "A mailing list for discussion about Sun Microsystem's Java > >Servlet API Technology." > > >To: [EMAIL PROTECTED] > > >Subject: Re: servlet to read a file > > >Date: Tue, 9 Oct 2001 09:25:25 +0530 > > > > > >First of all let me tell you that I am using NT platform. > > >Next you get c:\tomcat\jakarta-tomcat-3.2.3\webapps\Root\Note.txt (Root > > >instead of examples). > > >It means that you must keep your Note.txt file in Root directory J > > >I think that your URL in browser should be > > >http://localhost:8080/examples/servlet/MyServlet . Is that so? > > > > > >Hirdesh > > > > > > > >_________________________________________________________ > >Do You Yahoo!? > >Get your free @yahoo.com address at http://mail.yahoo.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 > > > > >---------- >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 ___________________________________________________________________________ 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
