JSP Example using Eclipse IDE :-


The step by step process of using Eclipse IDE to create and run JSP applications is as follows -

Here we are using Eclipse Oxygen and Apache Tomcat8.0.27.

1- Open Eclipse go to File -> New -> Dynamic Web Project.



2- It will open new Dynamic Web Project window. Enter project name, In our example project name is JSPDemo-



3- From Target runtime, select New Runtime button to configure Tomcat server -



4- It will open New Server Runtime Environment window, Select Apache tomcat version, that you have installed in your system, In our example, we selected Apache Tomcat v8.0.



5- Click Next and it will ask you to Browse the location of your Apache Tomcat Server. Browse the location of your installed Tomcat.



6- Click Finish, and it will configure Apache tomcat for your application.



7- From New Dynamic Web Project window click Next.



8- Again click Next and it will open the following windows -

Click on the Generated web.xml deployment descriptor checkbox. It will generate web.xml file for you. And finally click Finish
9- It will create a project structure as shown below -



10- Right Click on folder WebContent, and go to New -> JSP File.

11- It will open New JSP File window, Name the file index.jsp and click Finish. It will create an index.jsp file in your WebContent Folder.



Note - This index.jsp file will be your default page i.e. when you run your project it will be your welcome page.
12- Make changes in your index.jsp page as shown below -
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<form method="post" action="First.jsp">
 Name - <input type="text" name="t1"><br>
 <input type="submit">
</form>   
</body>
</html>


13- Again Right click on WebContent folder, and go to New -> JSP File . Enter name of file (First in our example) and click Finish.



14- Make changes in your First.jsp page as shown below -
 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<h1>My First JSP Page</h1>
        <%
        String name = request.getParameter("t1");
        out.println("Welcome "+name);  
        %>
 <%-- out is an implicit object of javax.servlet.jsp. JSPWriter class available in JSP.  --%>
</body>
</html>   

15- TO run your project, Right Click on Your Project and go to Run As -> Run on Server.



16- It will open a Run on Server window, Select your server from the given list and click Finish.



17- Now it will show you the default page (index.jsp) on your web browser as follows -



Enter name in textbox and press submit button, and it will show you the following output -



Download this example - Click Here