Approaches to Web Development for Bioinformatics

Previous  Contents  Next
References

Servlets

Perhaps a good way to start is to look at a simple Servlet.  Java code can execute within an application server associated with a web server using Java Servlets.  The first step is to create a web application. If you are in Eclipse you can create a dynamic web project. I called my web application 'bio' and the root is a directory with the same name. This class is a simple example of a Servlet. The source code is in file HelloServlet.java.


package net.medicalcomputing.web;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* A basic Servlet
*/
public class HelloServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

/**
* Processes a GET HTTP request
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
PrintWriter writer = response.getWriter();
writer.println("Hello J2EE!");
}
}

Create a directory called WEB-INF within bio. Within WEB-INF you need to define a web application file called web.xml. Here is my web.xml file. I have mapped the Servlet to a relatvie URL of 'hello'.

You will need to compile the class with a Servlet API jar file. Place the compiled class in the directory bio/WEB-INF/classes. You can optionally bundle the directory structure into a Web Application aRchive (WAR) file, like bio.war. Place this in the webapps directory of your application server and try it out by bringing up the page 'http://localhost:8080/bio/hello', making allowances for the host name and port of your server.


Previous  Contents  Next
References

Contributed Comments and NotesAdd a comment.

There are no user comments.

Google

Please send ideas and opinions by email at alexamies@gmail.com.

© 2006-2007 Alex Amies