?
Solved

how to write a stream to a servlet without socket!!

Posted on 2004-11-17
3
Medium Priority
?
245 Views
Last Modified: 2010-04-01
how to write a stream to a servlet without socket!!
And how can I get rhe response ( something like response.getWriter() ??)

Thanks

0
Comment
Question by:aimueller
  • 3
3 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 12612931
This will read the output from the servlet...  But what do you mean by "write a stream to a servlet"?  servlets accept request objects and parameters, not streams...

    try
    {
        URL url = new URL("http://hostname:80/cgi");
        URLConnection conn = url.openConnection();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null)
        {
            // Process line...
        }
        rd.close();
    }
    catch (Exception e)
    {
    }
0
 
LVL 35

Accepted Solution

by:
TimYates earned 150 total points
ID: 12613167
Actually, I am wrong...  you can do request.getInputStream(), so why don't you simply use:

    try
    {
        URL url = new URL("http://hostname:80/cgi");
        URLConnection conn = url.openConnection();
        conn.setDoInput( true ) ;
        conn.setDoOutput( true ) ;
        OutputStream os = conn.getOutputStream() ;

         // then just write to the output stream...

        // and get the response :-)
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null)
        {
            // Process line...
        }
        rd.close();
    }
    catch (Exception e)
    {
    }
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12624827
Bah...only a B grade?

Oh well...good luck with it...

Tim
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question