Hi experts,

    Just consider this code.  I am writing some data to the servlet with no probs
and reading them.  My problem is that i need to write the stream variable into a
servlet variable and need to read that variable from that servlet.  Now i am
getting only the "This is" as output not the success i have written and also i
want to do some manipulation on the variable i am passing out.  Please help me to
solve this error.  Another problem is that i am unable to read the stream in the
fly since it needs a character array i was forced to declare that at the start
since i know the variable length and other things in the fly how shall i read the
data?  Please help me to solve this error.

My Servlet code is as follows:
======================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


public class sri extends HttpServlet
{
        public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
        {
                PrintWriter out = res.getWriter();
                out.println("This is a testing servlet");
        }
}

My Java Code is as follows:
====================
import java.io.*;
import java.net.*;

public class five
{
 static char[] c = {'s','u','c','c','e','s','s'};
 public static void main(String[] args)
 {
  String mainURL = "http://164.164.61.118:8080/servlet/test";
  try
  {
   String sri = "success";
   int x = 0;
   URL url = new URL(mainURL);
                  System.out.println("The url is " + url);
   URLConnection urlc = url.openConnection();
   urlc.setDoOutput(true);
   OutputStreamWriter osw = new OutputStreamWriter(urlc.getOutputStream());
   osw.write(sri,0,sri.length());
   osw.close();
   System.out.println("I am near input");
   InputStreamReader isr = new InputStreamReader(urlc.getInputStream());
   x = isr.read(c,0,6);
    if ( (x != -1) )
    {
     String fin = new String(c);
     System.out.println("The final str is " + fin);
    }
    else
    {
     System.out.println("Couldnt read from the test");
    }
   isr.close();
    }
  catch(MalformedURLException mfe)
  {
   System.out.println("The message is " + mfe.getMessage());
  }
  catch(IOException ioe)
  {
   System.out.println("The io error is " + ioe.getMessage());
  }
 }
}

___________________________________________________________________________
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