Results 1 to 4 of 4
  1. #1
    yemista is offline Member
    Join Date
    Oct 2011
    Posts
    41
    Rep Power
    0

    Default cant connect to servlet

    I wrote some code to connect to my servlet.

    Java Code:
    String charset = "UTF-8";
                        System.out.println("msg "+message);
                        String urlParameters = "jsessionid=" + URLEncoder.encode(sessionid, "UTF-8") + "&text=" + URLEncoder.encode(message, "UTF-8");
                        site = new URL("http://localhost:8085/TutorHorizons/InputServlet?"+urlParameters);
                        System.out.println(site);
                        connection = (HttpURLConnection)site.openConnection();
                        //connection.setRequestProperty("Accept-Charset", charset);
                        connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                        connection.setRequestMethod("GET");
                        connection.setDoOutput(true);
                        //connection.setReadTimeout(10000);
                        //connection.setDoOutput(true);
                        //connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
                        connection.connect();
    i left the commented stuff in so you could see other things i tried. this code wont work, however, when i paste the url that prints out into a browser, it connects just fine. any suggestions?

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: cant connect to servlet

    Did you get any error message when running the program?

  3. #3
    yemista is offline Member
    Join Date
    Oct 2011
    Posts
    41
    Rep Power
    0

    Default Re: cant connect to servlet

    Nope, no exceptions thrown at all. Also, when I use the same code to connect to google.com and read from it, I get data.

  4. #4
    yemista is offline Member
    Join Date
    Oct 2011
    Posts
    41
    Rep Power
    0

    Default Re: cant connect to servlet

    ok its working now. one thing that was wrong was in the servlet itself, i was calling flush on the output stream and it didnt like that. also, it seemed to be a combination of netbeans acting funny and running wireshark on my machine. i have no clue how these factors screwed things up, but after a restart everything worked just fine. i debugged it by printing out the httpresponsecode

Similar Threads

  1. connect servlet and jsp in tomcat
    By abcdef in forum Java Servlet
    Replies: 1
    Last Post: 02-18-2011, 12:04 PM
  2. J2EE = Servlet+Mysql connect
    By initmax in forum Java Servlet
    Replies: 2
    Last Post: 10-30-2009, 09:42 AM
  3. J2EE = Servlet+Mysql connect
    By initmax in forum Java Servlet
    Replies: 2
    Last Post: 10-30-2009, 07:57 AM
  4. Replies: 1
    Last Post: 12-02-2008, 12:23 AM
  5. Replies: 1
    Last Post: 08-07-2007, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •