JSP allows you to embed snippets of the Java programming language into HTML tags to create interactive content. HTML pages are static in that each time a user loads the page, the content will appear the same. JSP allows for dynamic content to be added to HTML pages, so that each time the user reloads the page, the content changes. For example, we will go through a sample where every time a user reloads the page, the date and time are changed automatically to reflect the current date and time.
Step 1
Open a new page in Notepad. Type the beginning and closing HTML tags with some space in between both tags. This specifies that the content will be in HTML.
Video of the Day
Step 2
Type the opening body tag in the line below and the closing body tag in the line directly above . Keep some empty lines between the opening and closing body tags. The rest of the lines between these two tags will specify the action the website will follow:
Step 3
Insert the following line at the top before the tag: <%@page contentType="text/html" import="java.util.*" %>
This line declares that we are importing the java.util package because we will be using the date function. Java packages consist of classes of related functions.
Step 4
Insert the following tag after the
tag: <%= new java.util.Date() %>. The <% and %> are JSP tags that specify an action needs to be taken with the function that is provided.Step 5
Save the page with a .jsp extension.
Video of the Day