This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes how to send a string to a servlet from a java program Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "how to send a string to a servlet from a java program" Watch "how to send a string to a servlet from a java program" New topic
Author

how to send a string to a servlet from a java program

Mei-Mei Ho
Greenhorn

Joined: Mar 02, 2012
Posts: 1
I have a simple piece of code to attempt connecting to the servlet url and invoke the doPost in the servlet to send along a string (actually I am trying to send some xml strings eventually, but just want to see if this simple string will work first). I put a break point in the servlet doGet or doPost method and it's not stopping there at all! But when I just go straight to that servlet from Internet explorer by typing in http://localhost:8080/Testing Servlets/hello in the address, it hit the servlet's break point, so that's why I know that this piece of HTTP_poster code does not seem to hit that servlet when I run it on the command line. It doesn't even print the "cannot send the string to servlet" in the catch! So I am not sure where it sent to then! I am running the servlet in a simple Tomcat 6.0 environment. Any help or wisdom would be very appreciated. Thanks!


The servlet code is also quite simple:
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16487
    
    2

For one thing the URL in your sending program is not well-formed. It needs to be URL-encoded: so instead of "http://localhost:8080/Testing Servlets/hello" it should be "http://localhost:8080/Testing%20Servlets/hello". (Browsers do this on your behalf without telling you.)

However I would fix that by not having a space in the application's context name -- that space leads to too much confusion.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to send a string to a servlet from a java program
 
Similar Threads
Firewall Tunelling using Servlet Technology
Calling Servlet from SQL Server Stored Procedure
Uploading Image from Java Desktop App to Server
Can a servlet architecture download a file?
URLConnection to servlet