Implementing JSP on NetBeans IDE


Let’s say you want to start learning JSP with a thorough understanding of an IDE. For that, the procedure is easy, you can go with NetBeans IDE and Eclipse IDE. These two IDEs are widely used and here we are going to discuss about beginning with JSP on NetBeans IDE.

We shall not consider the default server under NetBeans IDE i.e GlassFish. Instead we shall use Apache Tomcat Server for the same purpose. Before we start the actual process, let us see the technologies which we shall use to accomplish our purpose.

Terminology

We should get some idea of the technologies and terminologies we are going to use further in this article.

IDE: IDE stands for Integrated Development Environment that consists of a source code editor, a debugger, and build automation tools. The most popular multiple-language IDEs include Eclipse, NetBeans and Visual Studio.

NetBeans IDE: It is a free and open-source development platform written in Java. It provides multi-language support.

Java: It is a programming language developed by James Gosling and as a software platform it was initially released on 23 January 1996.

Java Server Pages: Java Server Pages or JSP is a server-side programming technology to create web applications.

Apache Tomcat Server: It is an open-source web server that implements various Java EE specifications: Java Servlet, JSP, Java EL, and WebSocket. It was initially released in 1990 and developed by the Apache Software Foundation.

Implementing JSP on NetBeans IDE

Starting with implementing JSP on NetBeans IDE is easy and here we will discuss about a simple project to make it easier for beginners. Follow the below given steps −

Step1 −

Download NetBeans IDE from NetBeans official website and install it on your computer. On opening the link you will find the following. I have downloaded the yellow marked one as in the following screenshot. While installing add the JAVA path i.e. download java before installing NetBeans IDE.

Download_NetBeans_IDE

Step 2 −

Open NetBeans IDE & click File menu and click New Project as in the following screenshot −

new_project_in_netbeans

Step 3 −

After clicking New Project, you will get the following dialog box. Select Java Web, after that Web Application. Now click Next to proceed further.

select_web_application_in_netbeans

Step 4 −

A new dialog box will open; now add project name and location. You can add any name; I have mentioned the project name as AmitWebApplication and kept the location as it is. After that click Next.

add_project_name_in_netbeans

Step 5 −

Now you need to select a server, b y default glassfish server is provided, but we will consider Apache Tomcat Server as mentioned before.
default_server_glassfish_in_netbeans
For that got to download Apache Tomcat 7 page and download 64-bit Windows zip (pgp, md5, sha1). I am having a Windows 10 64-bit OS, so I downloaded the 64-bit version.

Place the file in C: drive (you don’t need installation because we did not download the installer), so your final path for Apache Tomcat on my system is −

C:\apache-tomcat-7.0.67

After installing return back to NetBeans IDE and click Add in the same dialog box as in the following screenshot. You will see a list of servers under Add Server Instance dialog box.
adding_tomcat_in_netbeans

Now select Apache Tomcat and click Next
select_tomcat_in_netbeans

The new dialog box will ask for adding the server location. Add the path where you installed Apache Tomcat Server. The path is −

C:\apache-tomcat-7.0.67

Here’s the screenshot −

server_location_in_netbeans

Now, click Finish. After clicking, you will return back to Add Server dialog with Server as Apache Tomcat as in the following screenshot −

tomcat_in_netbeans

Step 6 −

After that click Next and do not select any Framework since we’re considering a simple program here. Click Finish.

Step 7 −

Now you can see the following default JSP will open. Also, check the directory structure on the left in the following screenshot. You can see the file index.jsp under web folder −
index

Now edit the JSP file; here’s the edited code. We will just add some text to print the date and time. For this, I have taken an example of JSP Expressions.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <title>First JSP Page</title>
</head>

<body>
   <h1>Today's date</h1>
   Date and Time: <%= (new java.util.Date().toString())%>
</body>

</html>

Step 8 −

Now to run the index.jsp file, build the project as in the following screenshot. Right click on the project “AmitWebApplication” and click Build

build_project_netbeans

After that you can see that the project build works fine.
build_successful_netbeans

Now, click F6 to run the project. You can also click on the following toolbar button −

run_project_in_netbeans

Here’s the output if everything works fine. You can check the title, heading, and the date-time we printed using JSP Expressions. The project is executing on localhost, so the link is −

http://localhost:8080/AmitWebApplication/
output_in_netbeans

Conclusion

So, this was a beginner tutorial to start with JSP on NetBeans IDE. Here we considered Apache Tomcat Server and created a sample web application in JSP. Through this tutorial you learned −

  • How to start with NetBeans IDE.
  • How to set Apache Tomcat Server in NetBeans IDE.
  • How to start with your first JSP program in NetBeans IDE.
  • How to successfully run a JSP web application in NetBeans IDE.

If you have any questions, then please mention in the comments section.

Other Interesting Posts

Advertisements