JSP
JSP Current Date and Time
JSP Date Handling All methods of core Java can be used in JSP is the biggest advantage of JSP. In...
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-
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 - https://www.gtupapers.com/install-java.html
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:
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:
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.
Installation of Jboss has been done, and server can be accessed from here.
The server has been started successfully.
Step 1) We can create a dynamic web project by right clicking on the project explorer, and we get the following window:
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.
Once we click on finish button, the project is created and seen on the explorer with the following folders.
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.
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:
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.
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.
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.
Step 3) Once you click on finish button, a new window will pop up.
There are two options,
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.
When we click the finish button, then the project is deployed on the server and message can be seen in following screen shot.
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.
Output:
This is Guru JSP text from the guru_example.jsp
Summary:
JSP Date Handling All methods of core Java can be used in JSP is the biggest advantage of JSP. In...
What is JSP Action? JSP actions use the construct in XML syntax to control the behavior of the...
What is JSP LifeCycle? JSP Life Cycle is defined as translation of JSP Page into servlet as a JSP...
What is JSP Implicit object? JSP implicit objects are created during the translation phase of JSP...
The database is used for storing various types of data which are huge and has storing capacity in...
What Is Servlet? A servlet is a Java technology that is managed by a container called a servlet...