File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Connecting to the webserver from simple java program with main method 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 » Beginning Java
Bookmark "Connecting to the webserver from simple java program with main method" Watch "Connecting to the webserver from simple java program with main method" New topic
Author

Connecting to the webserver from simple java program with main method

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi Folks,

i am try to connect the server with URL but server is not getting called[the particular servlet not getting called].

Here is my code



any suggession ?
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Any exception ?
And if not then, you are not printing the response, try this code after you "connected"




[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Sagar Rohankar wrote:Any exception ?


No Exception . and i am calling the servlet right? the servlet not getting called . in other term i need to call a servlet [web server is running] from simple java program .
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

seetharaman venkatasamy wrote: the servlet not getting called .

That's mean, you can call servlet using browser, but not from Java app. OK
Try changing the URL Connection class to base class, like

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

I may be wrong, but I think that openConnection only creates the connection - it does not actually do a request. Try if a request is made if you call "connection.getInputStream()" just before you print CONNECTED.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Sagar Rohankar wrote:
seetharaman venkatasamy wrote: the servlet not getting called .

That's mean, you can call servlet using browser, but not from Java app. OK

Sure you can. A HTTP server or servlet container doesn't care where the requests come from (although the web pages may).

Try changing the URL Connection class to base class, like


That's not the issue; connection will still be a reference to a similar object. You just use a different reference.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Rob Prime wrote: Try if a request is made if you call "connection.getInputStream()" just before you print CONNECTED.


Wonderful Rob. Excellent ,It is working
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

seetharaman venkatasamy wrote:
Rob Prime wrote: Try if a request is made if you call "connection.getInputStream()" just before you print CONNECTED.

Wonderful Rob. Excellent ,It is working

Why people ignore me I replied the same thing, look at the very first reply.

Rob Prime wrote:Sure you can. A HTTP server or servlet container doesn't care where the requests come from (although the web pages may).

No, I want to say, Is it your servlet URL is correct, means If you can call it from browser, then we confirm about the problem in Java code and not in URL/server/servlet. I'm just making it sure
And second point about reference , really dosen't a make a sense, its my wild guess (after, he ignore what I recommended in first place )
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Sagar Rohankar wrote:
Why people ignore me I replied the same thing, look at the very first reply.


Ohh Dear Sagar , Infact i got the point from rob post , but really sorry to forget you
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Sagar Rohankar wrote:
Why people ignore me I replied the same thing, look at the very first reply.


Ohh Dear Sagar , Infact i got the point from rob post , but really sorry to forget you
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

seetharaman venkatasamy wrote:
Ohh Dear Sagar , Infact i got the point from rob post , but really sorry to forget you

No apologizes please, I'm just kidding. The thing is I thought you tried out what I suggested in first place.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38062
    
  22
I'm pleased to see there are no hard feelings
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Sagar Rohankar wrote:
Rob Prime wrote:Sure you can. A HTTP server or servlet container doesn't care where the requests come from (although the web pages may).

No, I want to say, Is it your servlet URL is correct, means If you can call it from browser, then we confirm about the problem in Java code and not in URL/server/servlet. I'm just making it sure

Ah, I misunderstood. And the remark was very good indeed; it could very well have been the URL that was the problem.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Rob Prime wrote:
And the remark was very good indeed;

I'm honored to hear that from someone like you Rob
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to the webserver from simple java program with main method
 
Similar Threads
Thread timeouts
Unable to access URL using HttpURLConnection
I am getting HTTP Version Not Supported (505)Error
How to capture a response from a Server?
pass a file from a server to another using servlets or ?!.