abas
asked on
Calling java servlet
Hi,
Could you please tell me is there any way to call java servlet from a non-browser (without http protocol) client ??
I mean without using web browser,is there anyway to call java servlet ?
Baskar
Could you please tell me is there any way to call java servlet from a non-browser (without http protocol) client ??
I mean without using web browser,is there anyway to call java servlet ?
Baskar
Sorry - I misread your question - I thought you were referring to a server not browser. :oP
It is possible to "run" a servlet from the command line - you just use the main method as you would a normal java program, and then do whatever you need to do to test the servlet.
Ant
It is possible to "run" a servlet from the command line - you just use the main method as you would a normal java program, and then do whatever you need to do to test the servlet.
Ant
You can add this to your main program to test servlet.
URL url = new URL("http://servlet");
URLConnection urlConn = url.openConnection();
URL url = new URL("http://servlet");
URLConnection urlConn = url.openConnection();
you can telnet to port 80 ,
assuming your webserver is running on myhost.mydomain.com:80
and your servlet is /servlet/HelloWorld
then try
telnet myhost.mydomain.com 80
GET /servlet/HelloWorld HTTP/1.1
[ENTER]
[ENTER]
assuming your webserver is running on myhost.mydomain.com:80
and your servlet is /servlet/HelloWorld
then try
telnet myhost.mydomain.com 80
GET /servlet/HelloWorld HTTP/1.1
[ENTER]
[ENTER]
As for telnet, don't get confused when you type you don't see anything, because the webserver doesn't do character echo. Just type blindly the command "GET /servlet/HelloWorld HTTP/1.1" and hit enter
twice. Then telnet shows you the response in raw data.
twice. Then telnet shows you the response in raw data.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
From my book "core Servlets and JavaServer Pages" the author presented a web client to test servlets and JSPs without using a browser.
Just go to the link and look for "WebClient.java". This class needs some more helper classes.
WebClient opens a window, lets you submit a request with all headers and shows you the response with all headers. Very impressive!
http://archive.coreservlets.com/Chapter2.html
There is the contrary example, too: The EchoServer. This is a small utility to test what gets sended to a server when you submit a form or the like.
Cheers!
Just go to the link and look for "WebClient.java". This class needs some more helper classes.
WebClient opens a window, lets you submit a request with all headers and shows you the response with all headers. Very impressive!
http://archive.coreservlets.com/Chapter2.html
There is the contrary example, too: The EchoServer. This is a small utility to test what gets sended to a server when you submit a form or the like.
Cheers!
Why did you give harshita a low grade C? This is not fair.
Check out:
http://www.devdaily.com/java/edu/pj/pj010025/
http://rts.ncst.ernet.in/resources/java/tutorial/servlets/servletrunner/
:o)
Ant