FIRST SERVLET PROGRAM
REQUIREMENTS :-
1. SDK here we are using ECLIPSE NEON.
2. APACHE TOMCAT 7.0 Server to run the application.
STEP 1 :-
STEP 2 :-
2. APACHE TOMCAT 7.0 Server to run the application.
STEP 1 :-
- Open ECLIPSE
- Goto NEW now click on DYNAMIC WEB PROJECT
- Create PROJECT NAME
- Provide TARGET RUNTIME as APACHE TOMCAT v 7.0 (if not configured select "new runtime" and install apache tomcat)
- Click on NEXT
- Before FINISH select "Generate web.xml deployment descriptor"
- Now click on FINISH
STEP 2 :-
- You can now see a Dynamic Web Project on the left side in the navigation bar.
- Right Click on the project name select NEW >> SERVLET
- Provide a CLASS NAME to Servlet. Click on NEXT
- Before FINISH check "doGet()" and "doPost()" methods. Do not uncheck any checked checkboxes.
STEP 3 :-
- import PRINTWRITER as "import java.io.PrintWriter;"
STEP 4:-
- Move to doGet() method in the servlet
- Write the following code inside doGet()
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.print("<h1>Welcome To Servlet <h1>");
Save the project
STEP 5 :-
- Right click on the Project Name and Goto RUN AS >> Run On Server
- Check "Choose an existing server"
- You will now see a server listed below. In our Case we've configured APACHE TOMCAT SERVER.
- Click on FINISH
Server will start and a new window will open
In Case Of error Click On the URL and write the servlet name at last of the Url.
Now Reload the Web Page, You will get the desired result Now.
Comments
Post a Comment