wood burning stoves 2.0*
The moose likes Tomcat and the fly likes What sort of Java to use with my Tomcat server? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "What sort of Java to use with my Tomcat server?" Watch "What sort of Java to use with my Tomcat server?" New topic
Author

What sort of Java to use with my Tomcat server?

Isla Haper
Greenhorn

Joined: Nov 08, 2011
Posts: 4
Hi all,

This site kept appearing in my google quest for information so I thought I'd ask here directly.

I have spent the last few weeks figuring out how to deploy a tomcat6 server on a linux machine and it has an ajp connector set up also. Its all up and running now and I've played with some of the examples and they are all working.

What I am trying to do next is to make a standard java program to run on a client machine, not a browser based client.

I want this java program to send a simple String to the tomcat server where it will be processed and return a string.

I've looked at the sun tutorial on sockets but couldn't get it working and was told it wasn't an ideal solution. Could someone advise or link to some tutorials for something suitable?

Thanks in Advance,

Isla
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If for some reason you're set on using Tomcat as the server, then using HTTP makes more sense than using raw TCP/IP sockets. Here's an example of how a Java desktop app might access a servlet running inside Tomcat: http://www.exampledepot.com/egs/java.net/ReadFromURL.html. The URL can contain parameters so that the servlet's response can vary according to the input it gets.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Also read http://www.exampledepot.com/egs/java.net/Post.html (which is linked to from that page) for how to do a POST request instead of a GET request.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Isla Haper
Greenhorn

Joined: Nov 08, 2011
Posts: 4
Thanks Guys, I'll try out the HTTP method.

But if I really really wanted to do sockets could I do it?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

It depends what you want to connect to. You can always implement HTTP requests with raw sockets but you really don't want to. You can connect to the AJP connector directly if you understand its communication protocol. You can have a web application start a separate server socket and connect to that. However, the simplest way remains using URL and HttpURLConnection (or a library with a higher abstraction level like Apache's HttpClient) to connect to an existing HTTP servlet or JSP page.
Isla Haper
Greenhorn

Joined: Nov 08, 2011
Posts: 4
Thanks Rob, sorry if I sound a bit dumb, its all very new.

The functionality I want is identically to that shown in in the knock knock tutorial: http://download.oracle.com/javase/tutorial/networking/sockets/clientServer.html

Is there a tutorial showing a similar thing for HTTP?

Edit: Also seen as the client program will be a GUI run locally on the desktop will HTTP still be the right tool for the job?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15665
    
  15

The main reason why you'd want to use the Http connection classes instead of brute-force socket communications is the extra support you'll get.

The HTTP classes use the raw sockets as their underpinning, but they automatically handle the unique requirements of the HTTP protocol. They automatically manage headers and cookies, they parse out HTTP objects and response codes, and they make it simpler to construct a POST data stream.

It really doesn't matter about the form and nature of the client. Regardless of whether the client is a stand-alone Application, an applet, a mobile app or something else entirely (including another server), you'll benefit by using the Http classes if you intend to talk to an HTTP server like Tomcat.


Customer surveys are for companies who didn't pay proper attention to begin with.
Isla Haper
Greenhorn

Joined: Nov 08, 2011
Posts: 4
Thanks Tim, half the battle is understanding the different methods.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What sort of Java to use with my Tomcat server?
 
Similar Threads
servlet filter to hain System.out to jsp out.println() -Challenge !-
Tomcat to BEA Weblogic
Tomcat to BEA Weblogic
Can't connect to my web service remotely (very basic example)
Can I Have Two-Way Communication with Sockets with just one Port?