• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java client talking to servlets

 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have some servlets which work fine(posting,getting contents to/from a database) when invoked from a browser.Now i am interested to run the same application from the command prompt i.e without using a browser and invoking the servlets from the command prompt.Can anyone kindly let me know of a way to do this or suggest any good resource that I could use.
Thanks
Ashwin
 
Suneel Setlur
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
You can still write the entire commands to make the connection to the database and query/create/insert/udate from a standard java program. You can even create a front end using swing/awt to display retrieved data.
You can invoke the file thru the standard java command at the command prompt.

------------------
Suneel
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Suneel,
Thank you very much for the advice,but I am confused a little bit here.Are you suggesting to use straight JDBC code without any servlets for doing the posting & querying,but then I want to use servlets for that purpose.Could you please explain to me on what I should do to make it work.
Thanking You
Ashwin

 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what are you trying to do - may be you need to separate logic from ui, and have some object, that both servlet and your app will use?
if you need just run your servlet from command line, you need:
iexplorer "you servlet address and parameters",
for example:
iexplorer "http://localhost/search?a=100&b=18"
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Yurey;
Thanks for the reply,I will try to clarify something here.My servlets are working fine under windows environment(I can invoke them using IE as you have just said by the following line:- http://myhostname:80/servlet/MyServletName.
Now I want to run the same application in an unix world or a main frame world without a browser,but just only from ordinary java clients.These java clients will invoke my servlets and the servlets will do the necessary database work(inserting/querying).
So could you now please suggest me a way of doing this(calling servlets from command prompt).
Thanking You,
Ashwin
 
Yuriy Fuksenko
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if all that you need is send request to a server, you coud do something like:
URL u = new URL("http://yourURL");
BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream()));
you can even read the output from your servlet and analize it.
 
Srikanth Devaraju
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I think you want use servlets for non-browser client. I that case you need to change the servlet a little bit. Instead of inherting servlet from httpServlet, you have inherit from just servlet. Because httpServlet expects that the client should be the browser and protocal used to be the HTTP. But I think you want run the servlets in ordinary client - server model. So you should inherit your servlets just from the servlet.
In this clinet/Server model servlets act as a Server. But they don't send any HTML code back to you, because you are not using bowser clinet and not HTTP protocal. So your clent server model become socket client and socket server(Where servelets listen on a port). For user interface(GUI) you have develop some thing may be applets or any thing else. I hope this will put you on right trac.
Regards,
Srikanth
 
George Toronto
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ashwin,
Do you know how to run a simple servlet which just prints "hello world" in console? If you mean just do that, I think the answer is easy. Plz tell me the your thinking.
rgds
George
 
Ashwin Tadepalli
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi (Yuriy, Srikanth & George),
First of all let me thank you very much for giving me your valuable insights.I am somewhat following on what you have to say,especially of Srikanth saying to use a servlet inheriting from servlet class.Now coming to you George, yes I want something of very simple nature as a hello world application right now to be displayed on the console but would like to extend it further to include database processing for the servlet to do posting, getting, querying and deleting of records in the database.I have got some idea for now to use the URL class to do that.So if you could send me some sample code or any resource that I could use on this topic,I would really appreciate that.
Thanking You,
Ashwin
 
Laojar Chuger
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check information on topic of the Applet-Servlet communication. Suppose you can run an Applet like application from java console and this applet use RMI or sockets to talk with servlet. Then you may keep all the code you have.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic