The Artima Developer Community
Sponsored Link

Java Answers Forum
Http connection from applet

3 replies on 1 page. Most recent reply: Jun 24, 2003 4:59 PM by John

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Fredrik Forsberg

Posts: 2
Nickname: fredrikf
Registered: Jun, 2003

Http connection from applet Posted: Jun 17, 2003 4:23 AM
Reply to this message Reply
Advertisement
I have a problem with my http connection from an applet to a servlet. I connect to the servlet and the code looks as fine as any other working example I've looked at. The problem is that nothing happens at the servlet when I send data. But, the servlet reacts fine when I call it from a web browser. Why? The URL is the same.


Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

Re: Http connection from applet Posted: Jun 17, 2003 10:06 PM
Reply to this message Reply
Cast back the URLConnection of servlet to HttpURLConection,
set the request method to POST

java.net.HttpURLConnection servletConnection = (java.net.HttpURLConnection) url.openConnection();
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setRequestMethod("POST");

and write data onto stream.

Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: Http connection from applet Posted: Jun 18, 2003 2:41 AM
Reply to this message Reply
My suggested answer to a similar question at

http://www.artima.com/forums/flat.jsp?forum=1&thread=3005

may also prove helpful.

Adam

John

Posts: 2
Nickname: asperdude
Registered: Jun, 2003

Re: Http connection from applet Posted: Jun 24, 2003 4:59 PM
Reply to this message Reply
The URLConnection class is a little tricky to use. You have to do things in the right order. If you do not call doOutput(true) and get the output stream before you get the input stream the URLConnection class will generate a GET request. However, if you do set doOutput() and get the output stream and then close the output stream before opening the input stream you will end up with a POST request.

Flat View: This topic has 3 replies on 1 page
Topic: How to stop a Thread? Previous Topic   Next Topic Topic: Compiling problem with javac.Main.compile

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use