Results 1 to 4 of 4
Thread: cant connect to servlet
- 08-18-2012, 05:03 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 41
- Rep Power
- 0
cant connect to servlet
I wrote some code to connect to my servlet.
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?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();
- 08-18-2012, 10:58 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
Re: cant connect to servlet
Did you get any error message when running the program?
Website: Learn Java by Examples
- 08-18-2012, 02:28 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 41
- Rep Power
- 0
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.
- 08-18-2012, 05:18 PM #4
Member
- Join Date
- Oct 2011
- Posts
- 41
- Rep Power
- 0
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
-
connect servlet and jsp in tomcat
By abcdef in forum Java ServletReplies: 1Last Post: 02-18-2011, 12:04 PM -
J2EE = Servlet+Mysql connect
By initmax in forum Java ServletReplies: 2Last Post: 10-30-2009, 09:42 AM -
J2EE = Servlet+Mysql connect
By initmax in forum Java ServletReplies: 2Last Post: 10-30-2009, 07:57 AM -
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 12:23 AM -
javax.servlet.ServletException: Wrapper cannot find servlet class util.t2
By osval in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 03:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks