views:

99

answers:

3

Hi, I've coded some algorithms in java and I need to include those algorithm in my web application.

I'm using Apache Tomcat and what I need to do is that when, for example, I click on the start button on my web page a java class should be executed. I think this done by using servlets, am I right? If so, do you know where I can find some literature about it? I've searching in internet but it's al little bit confusing for me.

Thanks!

+1  A: 

Yes, you're right. You'd want to write a servlet that handles request to an URI. Here's some introduction:

Tomcat comes with some samples, you might look at the source code as a start, they should be in the webapps/sample directory. The Tomcat documentation is also a good start.

nos
A: 

I would check out this introduction to servlets

A servlet receives an HTTP request (e.g. a request for a page etc.). It will process that request via the methods doGet() or doPost(), and return an HTTP response. That response will contain your results (most likely an HTML page, although that's not mandatory).

I would (in order)

  1. get a static 'hello world' page going
  2. get a static page returning some data from your libraries
  3. get a dynamic page returning some data from your libraries using data from the HTTP request

Integrating your library will be trivial, since a servlet is simply a Java class that can instantiate/call on any other Java class.

Brian Agnew
A: 

You will need to learn how to use Java in a web server. I would recommend using JSP just to start with as it allows you to create web pages that call Java code easily.

There are many JSP tutorials on the net - I believe this one is suitable: http://www.jsptut.com/

Thorbjørn Ravn Andersen