This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Calling servlet from java, why does this code dosent work ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling servlet from java, why does this code dosent work ?" Watch "Calling servlet from java, why does this code dosent work ?" New topic
Author

Calling servlet from java, why does this code dosent work ?

Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
I try to call a servlet in my websphere application server, it works fine when i type in the url in the browser.....

Now i want to do the same from a java standalone program, in my class that extends TestCase "junit class"....

The code runs fine, no exception, but i have a hello world in the dopost and the doget, i dont get called the servlet....

No exception, nothing, can anyone tell me WHY ?



Frank
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

You have to read the response on the client end. If you don't, the server throws your request away because you aren't following the HTTP protocol.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
Write to the responce on the client, i dont know what you mean ? , the connection.getoutputream() is in the constructor to the OutoutStreamWriter.....

And i say out.write ......

Is there more ?

Frank
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
Yes, there's more to it :-)

Right now, the code only sends a request, and completely ignores the server's reponse. Hence the problem Joe mentioned. Here's an example of how to read the response.


Ping & DNS - my free Android networking tools app
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
Oh now i know what you mean, but i dont want to read the responce, i just want to send some data to the servlet, and in the doPost / doGet methoed, i have a system.out.println("helle world");

But i dont get a hold on the servlet, i dont get print the messages in my log, but i works when i type in the url in my browser


Frnak
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41155
    
  45
It doesn't matter if you *want* to read the response - you *need* to read it. Nothing stops you from throwing it away if you don't care about it.

It works in the browser because the browser does read the response.
Frank Jacobsen
Ranch Hand

Joined: May 17, 2002
Posts: 348
It works

Do i have a link to somewhere when i can some information, i still dont now why i have to read the response, when im not using it

But thanks a lot for helping my out


Frank
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Frank Jacobsen wrote:i still dont now why i have to read the response, when im not using it


Because the protocol says you have to. If you picked up the phone and dialed someone and didn't say anything when they said "hello", they'd hang up. They wouldn't sit there and talk to themselves.
The same thing applies here. The server has picked up the phone and done their part of the protocol. Until you actually start your part of the protocol, they aren't going to start processing because doing so is a waste of resources, in the server's opinion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling servlet from java, why does this code dosent work ?
 
Similar Threads
Reading request.attributes() in my servlet dosent work, can anyone tell my why ?
Cannot access a servlet from a Java application
Unable to invoke servlet from client (simple java class)
call servlet with multipart, apache.commons.fileupload how ?
URLConnection writing problem