Two Laptop Bag*
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
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: 349
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: 8876
    
    8

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: 349
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: 41601
    
  55
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: 349
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: 41601
    
  55
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: 349
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: 8876
    
    8

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.
 
wood burning stoves
 
subject: Calling servlet from java, why does this code dosent work ?