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.
|
2) Create the html file:
As you can see that a project is created named first. Now let's explore this project.
|
For creating a html file, right click on WebRoot -> New -> html -> write your html file name e.g. MyHtml.html -> Finish.
|
As you can see that a html file is created named MyHtml.html. Now let's write the html code here.
|
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.
|
As you can see that a servlet file is created named Hello.java. Now let's write the servlet code here.
|
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.
|
Click on the source tab to see the source code.
|
Now change the welcome file as MyHtml.html in place of index.jsp.
|
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.
|
Now change the port number as 8888 in place of 8080 -> apply -> ok.
|
Now port number have been changed. For starting the server Right click on your project -> Run As -> MyEclipse server application.
|
As you can see that default page of your project is open, write your name -> go.
|
|