LearnFast.Ninja

Create java servlet project eclipse

This simple tutorial will show you step by step how to build java servlet project in eclipse. Also you will see how to write some code and how to run your project.

Step 1: Click File then New then click on Dynamic Web Project.


Step 2: Name your project then select target runtime (Apache Tomcat) then click Finish.




Step 3: In the Project Explorer right click the project folder then select New then add Servlet.


Step 4: Name the package and name your class then click Finish.




Step 5: Write some code in the doGet function. In the doPost you can call doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

       PrintWriter oPrintWriter = response.getWriter();

       oPrintWriter.print("Hello world!");

}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

       doGet(request, response);

}


Step 6: Select Run As then click on Run on Server.


Result:


Tags

java

eclipse servlet