0% found this document useful (0 votes)
82 views

Connecting Tomcat Server in Eclipse IDE

1) The document describes how to configure Tomcat server in Eclipse IDE and create a simple servlet program. 2) It involves defining a new Tomcat server in Eclipse, configuring the server location and JRE, and then creating a dynamic web project with a servlet class that extends HttpServlet and overrides the doGet method. 3) The servlet mapping is then configured in the web.xml file by adding servlet and servlet-mapping entries for the servlet class, allowing it to be accessed at a URL and displaying output to the browser.

Uploaded by

AKHILA KHODAY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Connecting Tomcat Server in Eclipse IDE

1) The document describes how to configure Tomcat server in Eclipse IDE and create a simple servlet program. 2) It involves defining a new Tomcat server in Eclipse, configuring the server location and JRE, and then creating a dynamic web project with a servlet class that extends HttpServlet and overrides the doGet method. 3) The servlet mapping is then configured in the web.xml file by adding servlet and servlet-mapping entries for the servlet class, allowing it to be accessed at a URL and displaying output to the browser.

Uploaded by

AKHILA KHODAY
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Connecting Tomcat Server in Eclipse IDE

1) Open Eclipse->go to window Menu->Show view-> Select other option

2) Expand Server menu-> select Servers


3) Server View

4) Click on the link provided in the Server view and it opens Define new
Server Window
5) In the Define new server window expand Apache Menu -> select
Tomcat v8.0 Server and click on NEXT

6) It opens Tomcat server window


a) click on Browse button it opens Browse window->select the tomcat
installation directory
Ex: C:\Program Files\Apache Software Foundation\Tomcat 8.0
b) Select the JRE as(jre1.8.0_161) and click on finish

7) Server view appears like this


8) Right click on the server in server view-> click on start

9) Server view after server start


Creating Servlet Program in Eclipse IDE

1) Create a New project of type dynamic project


Right click on project explorer->select New->go to other

2) Expand web Menu->Select Dynamic web Project->click Next


3) Opens Dynamic web project window ->
a) Enter project name (ServletDemo)

b) Select the Target runtime as Apache Tomcat v8.0(Installed tomcat)


and click on Next
c) Opens following window and click on Next

d) In webmodule window select the Generate Web.xml deployment


descriptor checkbox
e) Click on finish New project appears in the project explorer

4) Expand Java Resources-> in src folder right click and


a) create Java Class with Name Hello(ClassName/FileName) by
Extending HttpServlet class following code will be generated
b) right click on code window go to source Menu->click on
override/implement methods option

c) Select doGet(…) method checkbox in the window and click OK


d) In the auto generated doGet() method code
Remove super.doGet(req, resp); Line and
Add following code of line System.out.println(“Hello”);
Right click and run using Server Following window opens

It generates 404 error which means file not found error. To debug
this error we need to configure web.xml file

e) Configuring Web.xml file


Locate and open the web.xml file in following location in the IDE
ServletDemo\WebContent\WEB-INF\web.xml
Following is the code present in the web.xml
f) Add following code snippet in the web.xml file

<servlet>
<servlet-name>Hello</servlet-name> <!-- Name given to servlet -->
<servlet-class>Hello</servlet-class> <!--Path to servlet class created-->
</servlet>

<servlet-mapping>
<servlet-name>Hello</servlet-name><!--Name of Servlet given in previous tag-->
<url-pattern>/Hello</url-pattern> <!—URL pattern to access the file -->
</servlet-mapping>

Screen looks Like


g) Save the web.xml file and run Hello.java using server

Browser is blank but Hello is printed on the console

Now all Configurations are done servlet is working fine

You might also like