• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to the webserver from simple java program with main method

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any exception ?
And if not then, you are not printing the response, try this code after you "connected"


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm pleased to see there are no hard feelings
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:
And the remark was very good indeed;

I'm honored to hear that from someone like you Rob
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic