Andras,
thank you for the help. It works great.

Andi Setiyadi





                    Andras Balogh
                    <[EMAIL PROTECTED]>           To:     [EMAIL PROTECTED]
                    Sent by: "A mailing          cc:
                    list for discussion          Subject:     Re: reading and edit 
document on the fly in servlet
                    about Sun
                    Microsystem's Java
                    Servlet API
                    Technology."
                    <SERVLET-INTEREST@JAV
                    A.SUN.COM>


                    05/22/01 11:40 PM
                    Please respond to "A
                    mailing list for
                    discussion about Sun
                    Microsystem's Java
                    Servlet API
                    Technology."






Hi,

I think the problem  is when you are making the URLConnection.
You see you didn't write a loop so you receive only the first line.
Try like this instead:

  URL docs = new URL("http://myhostname/pnet"; + path);
  URLConnection docsConnection = docs.openConnection();
  StringBuffer sb=new StringBuffer();
  buffer = new BufferedReader(new
InputStreamReader(docsConnection.getInputStream()));

          while((docContent = buffer.readLine())!=null)
sb.append(docContent);
          buffer.close();

          out.println(sb.toString());



Also don't forget to out.close(). A try catch block should be there too to
catch the Exceptions and print it out.



Best wishes,

Andras.

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Andi
Setiyadi
Sent: 22 mai 2001 22:25
To: [EMAIL PROTECTED]
Subject: Re: reading and edit document on the fly in servlet


Thank you for pointing the error about "text.html", I mistyped it.
That part is correct, no new window is launched.   Referring to my previous
question, am I taking the right approach to read the content of the htm
files? I want to be able to capture the content as one big string, edit the
content and display the new edited content to customer.
I have tried using the code that I posted, it give me nothing ... after
clicking the link, just white space, not a single word.  I checked the
path, it is correct. I attached the code below.
Thank you.

Andi Setiyadi


import ...

public class PersonnetDocContents extends HttpServlet        {
     public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException     {
          int i;
          String path = "";
          String docContent = "";
          String docID = req.getParameter("docID");     //16 digit id
          BufferedReader buffer = null;

          res.setContentType("text/html");
          PrintWriter out = res.getWriter();

          for(i=1 ; i<4 ; i++)                          //each 4 ids
represent a folder name
          {
               path = path + docID.substring(0,4) + "/";
               docID = docID.substring(4);
          }

          path = "/docs/" + path + docID + ".htm";
          URL docs = new URL("http://myhostname/pnet"; + path);
          URLConnection docsConnection = docs.openConnection();

          buffer = new BufferedReader(new
InputStreamReader(docsConnection.getInputStream()));
          docContent = buffer.readLine();
          buffer.close();

          out.println(docContent);
     }
}

___________________________________________________________________________
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

Reply via email to