• Home
  • Testing
  • SAP
  • Web
  • Must Learn!
  • Big Data
  • Live Projects
  • Blog

In this tutorial, we are going to study the basics of writing and running a JSP. We will install Java and Jboss server on our machine as they are pre-requisites to run a JSP.

In this tutorial, you will learn-

Install Java

To install java, we need to check whether we have any older versions of JDK (Java Development Kit) on the machine. If yes, uninstall them.

Refer this guide to install Java - /install-java.html

Install Jboss Server

Step 1) Jboss server can be downloaded from the following link:

After downloading the latest version of the server from the link, we will get a zip file which needs to be unzipped.

After unzipping it, it takes to the below folder:

Install JSP with Jboss Server & Java

We can start and stop the server using start and stop exe from the bin folder.

Step 2)We can include the server into eclipse IDE using following way:

  1. Create a new server by adding name to it as localhost
  2. Select the version of server from the list of servers
  3. Server name will be added here as JBOSS v5 at localhost(the one which is selected in above two steps)
  4. Click on the finish button to complete the steps.

Install JSP with Jboss Server & Java

Need to define which version of the server we are using, and we can specify the path from which we have unzipped above.

Once we click on finish button, then the server would be added to eclipse IDE.

Install JSP with Jboss Server & Java

Installation of Jboss has been done, and server can be accessed from here.

Installation Testing

  • Once Java and Jboss server have been installed on the machine, we can start using them in the eclipse IDE.
  • In eclipse IDE, we check that there are no errors and java path has been set as an environment variable.
  • If above steps are executed successfully, then the server will start successfully.

Install JSP with Jboss Server & Java

The server has been started successfully.

Your First JSP

Create a dynamic web project

Step 1) We can create a dynamic web project by right clicking on the project explorer, and we get the following window:

Install JSP with Jboss Server & Java

Step 2) Once we click on next button in above screen, we get the following window, where we have to enter a project name and then click on finish.

  1. Name the project
  2. Click on finish button

Install JSP with Jboss Server & Java

Once we click on finish button, the project is created and seen on the explorer with the following folders.

Install JSP with Jboss Server & Java

Create a JSP

Step 1)In the gurutest project, right-click on the project and then click on New JSP Page.

Step 2) Following window will open, and it will help to create a new JSP in the project.

  1. Select the parent folder in the application directory
  2. Select the web content folder as JSP are created under that folder
  3. Enter the filename of the JSP.
  4. Click on finish button to complete the steps and JSP is created.

Install JSP with Jboss Server & Java

File Name given as guru_example.jsp and then clicked on next and then finish.

Once the JSP is created it is seen in the web content folder as below:

Install JSP with Jboss Server & Java

Following is the code for that:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Guru Example1</title>
</head>
<body>
<a>This is Guru JSP.</a>
</body>
</html>

Explanation of the code:

Code Line 1: Here we are defining the page directives like language which is set to java, contentType to text/html, pageEncoding to standard ISO-8859(we will be learning in more detail in JSP in Action article directives section)

Code Line 3-12: Here we have defined an html with text "This is Guru JSP" which is shown as the output.

Start Jboss server and deploy project

Step 1) In the eclipse IDE, in the servers section right click on the server which has been configured and there is an option to start the server.

Install JSP with Jboss Server & Java

Step 2) Once the server is started then we can deploy the gurutest project. In the project explorer, right click on the gurutest project and then click on Run on the server and we get the following options.

  1. Select server either choose existing server or define a new server
  2. Select the server which has already been defined.
  3. Click on the finish button.

Install JSP with Jboss Server & Java

Step 3) Once you click on finish button, a new window will pop up.

There are two options,

  • Either to choose existing server or
  • Manually configure the server

In this case, we have already configured the server in the above case. Hence we can select the configured server and then click on next.

Here we get the configured projects which are to be deployed.

Install JSP with Jboss Server & Java

When we click the finish button, then the project is deployed on the server and message can be seen in following screen shot.

Install JSP with Jboss Server & Java

When we try to access http://localhost:8080/gurutest/guru_example.jsp

Where,

Localhost: Our own host on which server is started and 8080 is the port for that

Gurutest: Project which has been deployed on this localhost

Guru_example.jsp: This is JSP, which we are trying to access.

Install JSP with Jboss Server & Java

Output:

This is Guru JSP text from the guru_example.jsp

Summary:

  • In this tutorial, we learned about installing Java and Jboss which are pre-requisites to run a JSP.
  • Also, we learned how to write a JSP and then deploy on the server.After deploying the project, we get the JSP output in the browser.

 

YOU MIGHT LIKE: