struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ted Husted <hus...@apache.org>
Subject Re: action-servlet communication problem
Date Fri, 06 Sep 2002 12:16:10 GMT
The best place to post a question like this is the Struts USER list 
where there are more people to help you.

-Ted.

zhilei wang wrote:

> I am trying to send  a string from struts action in one application to 
> servlet in another application. However, the following code doesn't work 
> and no string is received. I don't know if it's the problem on sending 
> side or on receiveing side.
> Can someone help me on solving the problem? Thanks.
> 
> Sending side:
> 
> public class SubmitAction extends Action {
>    public ActionForward perform(){
>     String string = " ********";
>     String toURL =
> 
> "http://localhost:8080/AnotherApp/servlet/servlets.ControllerServlet";
>        URL url = new URL(toURL);
>     URLConnection con = url.openConnection();
>     con.setDoOutput(true);
>     con.setDoInput(true);
>     con.setUseCaches (false);
>        con.setDefaultUseCaches (false);
>     con.setRequestProperty("Content-Type", "text/html");
>     con.setRequestProperty("Content-length", "" + string.length());
>     OutputStream outStream = con.getOutputStream();
>     OutputStreamWriter ostream = new OutputStreamWriter(outStream);
>        BufferedWriter out = new BufferedWriter(ostream);
>        out.write(string);
>        outStream.flush();
>        outStream.close();
>      return new ActionForward(toURL, true);
>    }
> }
> 
> Receiving side:
> 
> public class ControllerServlet extends HttpServlet {
>    public void service(){
>     InputStream in = request.getInputStream();
>     InputStreamReader rdr = new InputStreamReader(in);
>     BufferedReader buff = new BufferedReader(rdr);
>     String line;
>     StringBuffer results = new StringBuffer();
>     while (null != ((line = buff.readLine())))
>         results.append(line + "n");
>     buff.close();
>     String resultString = results.toString();
>    }
> }
> 
> If debug the code, buff.readLine() always return null.
> 
> 
> 
> _________________________________________________________________
> Join the world's largest e-mail service with MSN Hotmail. 
> http://www.hotmail.com
> 
> 
> -- 
> To unsubscribe, e-mail:   
> <mailto:struts-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
> <mailto:struts-dev-help@jakarta.apache.org>
> 
> 


-- 
Ted Husted, Husted dot Com, Fairport NY US
co-author, Java Web Development with Struts
Order it today:
<http://husted.com/struts/book.html>


--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message