Objectives :

  • Creating Servlet with Eclipse (Galileo) 3.5.1

  • Display on Apache Tomcat Server

Step: 1 Physical Folder

Eclipse workspace

Step: 2 Creating Dynamic web and Servlet

Accepting perspectives

Adding web Servlet

The above is loaded with the NetBean, and was static .

Now, add a Servlet using this wizard

The above can be set with this screen,too.

The final make up came out

the Code edited to

package sr1;
import java.io.*;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class HelloWorld
*/
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public HelloWorld() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see Servlet#init(ServletConfig)
*/
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
}

/**
* @see Servlet#getServletInfo()
*/
public String getServletInfo() {
// TODO Auto-generated method stub
return null;
}

/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Hello World");
out.close();

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

}
 

Step: 3 Runtime analysis

If server is already started, the prompt will ask you to restart the server.

The above actions would display a frame running the output from the Servlet1 "HelloWorld", which uses a method "doPost" to display some messages, as shown in the code.

You may view the server status, by pulling the lower block (Server Tab) as shown below. Also note that Servlet-project contains Deployment Descriptor

http://localhost:8080/Servlet1/HelloWorld