Phil Swenson wrote:

> This is actually close to being OT, but I think many are interested in how
> to do this.
>
> I'm trying to post to a JSP from a Java class.  I absolutely can't get the
> thing to work.  The post is always completely empty.  Here is my code:
>
>       URL url = new URL("http://www.blah.com/blah.jsp");
>       URLConnection connection = url.openConnection();
>       ((HttpURLConnection)connection).setRequestMethod("POST");
> (yes, I know the setRequestMethod is probably unnecessary)
>       connection.setDoInput (true);
>       connection.setDoOutput(true);
>       connection.setUseCaches(false);
>       connection.setRequestProperty( "content-type",
> "application/x-www-form-urlencoded" );

Insert here:

        connection.connect();

to actually go across the network and open the connection.  This is mentioned in
the Javadoc for the URLConnection class, and explicitly described, among other
places, in the Networking Trail in the Java Language Tutorial
<http://java.sun.com/docs/books/tutorial>.

>
>       PrintStream outStream = new
> PrintStream( connection.getOutputStream() );
>       String blah = "hey=there";
>       outStream.println(blah);
>       outStream.flush ();
>       outStream.close();
>
> I've hit JavaSoft message boards and tried everything that was posted...it
> just doesn't work.
>
> Please help if you have any solutions.
>
> phil
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to