struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "zhilei wang" <>
Subject action-servlet communication problem
Date Fri, 06 Sep 2002 05:35:13 GMT
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 =

        URL url = new URL(toURL);
	URLConnection con = url.openConnection();
	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);
  	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");
	String resultString = results.toString();

If debug the code, buff.readLine() always return null.

Join the world’s largest e-mail service with MSN Hotmail.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message