Tuesday, 29 September 2015

Creating Servlet in myeclipse IDE

Creating Servlet in myeclipse IDE

You need to follow the following steps to create the servlet in the myeclipse IDE. The steps are as follows:
  • Create a web project
  • create a html file
  • create a servlet
  • start myeclipse tomcat server and deploy project
1) Create the web project:
For creating a web project click on File Menu -> New -> web project -> write your project name e.g. first -> Finish.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE

2) Create the html file:

As you can see that a project is created named first. Now let's explore this project.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
For creating a html file, right click on WebRoot -> New -> html -> write your html file name e.g. MyHtml.html -> Finish.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
As you can see that a html file is created named MyHtml.html. Now let's write the html code here.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE

3) Create the servlet:

For creating a servlet click on File Menu -> New -> servlet -> write your servlet name e.g. Hello -> uncheck all the checkboxes except doGet() -> next -> Finish.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
As you can see that a servlet file is created named Hello.java. Now let's write the servlet code here.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE

Now let's make the MyHtml.html file as the default page of our project. For this, open web.xml file and change the welcome file name as MyHtml.html in place of index.jsp.
Creating Servlet in myeclipse IDE
Click on the source tab to see the source code.
Creating Servlet in myeclipse IDE
Now change the welcome file as MyHtml.html in place of index.jsp.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE

4) Start the server and deploy the project:

For starting the server and deploying the project in one step Right click on your project -> Run As -> MyEclipse server application.

The default port of myeclipse tomcat is 8080, if you have installed oracle on your system, the port no. will conflict so let's first change the port number of myeclipse tomcat server. For changing the port number click on the start server icon at the left hand side of browser icon -> myeclipse tomcat -> Configure server connector -> change the port number as 8888 in place of 8080 -> apply -> ok.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE
Now change the port number as 8888 in place of 8080 -> apply -> ok.
Creating Servlet in myeclipse IDE
Creating Servlet in myeclipse IDE

Now port number have been changed. For starting the server Right click on your project -> Run As -> MyEclipse server application.
Creating Servlet in myeclipse IDE
As you can see that default page of your project is open, write your name -> go.

Creating Servlet in myeclipse IDE

No comments:

Post a Comment