Hello Friends,
This tutorial is regarding development of Servlet program using Eclipse IDE. Eclipse IDE is very popularly used for development of various web based and java applications. Servlet applications are very easily developed using the eclipse IDE. Following are the simple steps for the same.
Step 1) Open the Eclipse IDE and set the Perspective to Java EE (if not set by default).
Step 2) Create a new Project from File -> New -> Dynamic Web project.
Step3) Enter the details for the project for e.g. Project Name, Target runtime, Configuration etc. For now, we can concentrate on Project Name and target Runtime. Target Runtime is used to set the runtime environment for your servlet programs. In this tutorial we will set up the Apache Tomcat server for running our application.
Step 4) Setting up the Target Runtime: Click the New Runtime button and select the tomcat version you have installed. Then click on Next.
Step 5) Now, browse to the tomcat lib folder path and click on finish. Also finish the Project creation wizard.
Step 6) At this stage the Project is created in eclipse. Now right click on the project and create new Servlet.
Step 7) Enter the details for your servlet file and click finish.
Add below lines in the doGet() function and save it:-
1 2 3 4 5 6 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello World from code2java"); } |
Then Right click on the project or code snippet and click Run As -> Run On Server. The server will start by itself and will run the program for you, if there is no error then the output will be printed.
Check the output 🙂
Hope this will help you. Please write your reviews at admin@code2java.com
Regards,
Nikhil Naoghare.
I DO THE SAME AS BUT APACHE STARTS AND SUDDENLY STOPS..
PLEASE HELP
THANKS
Hi Vishal,
I guess you have not installed the apache tomcat properly. What kind of error you are getting, please mention that.
Thanks.
Hi,
Thanks for your tutorial.. Its working good.. You have explained very clearly..