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. If I try replace service() with doPost() or doGet(), 
doPost() will give exception but doGet() won't. It seems that the request is 
not a Post request therefore open an InputStream from the request will fail. 
How could I create a Post request from struts action?

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();
    }
}



_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to