JSP
Web.xml Filter Mapping in JSP Servlet with Example
What is JSP Filter? Filters are used for filtering functionality of the Java web application. They...
All methods of core Java can be used in JSP is the biggest advantage of JSP.
In this section, we will be using Date class of java.util package, and it consists of date and time.
It supports two constructors:
Date() – It gives us current date and time
Date(long miilsec) – This takes parameter of milliseconds which has been elapsed on January 1 1970
Boolean after(Date date) – It gives after date of the given date parameter
Boolean before(Date date) – It gives the before date of the given date parameter
Object clone() – It creates a copy of the date object
IntcompareTo(Date date) – it compares the date class object with another one
IntcompareTo(Object date) – it compares with the object class object with another one
Boolean equals(Object date) – it checks whether two date objects are equal
Long getTime() – it fetches the time
InthashCode() – it fetches the hashcode of the given date
Void setTime(long Time) – It sets the time of given date object
String toString() – It converts into string object of date object.
Example:
In this example, we are fetching the current date and time using date object
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>
<!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 current Date</title>
</head>
<body>
Today's date: <%= (new java.util.Date()).toLocaleString()%>
</body>
</html>
Explanation of the code:
Code Line 11: We are using date object to fetch the current date and time.
When you execute the above code, you get the following output
Output:
We are getting current date and time
What is JSP Filter? Filters are used for filtering functionality of the Java web application. They...
In this tutorial, we are going develop sample programs with JSP and using MVC architecture....
What is JSP Implicit object? JSP implicit objects are created during the translation phase of JSP...
What is JSP Exception? Exceptions occur when there is an error in the code either by the developer...
What is JSP? Java Server Pages (JSP) is a technology which is used to develop web pages by...
What is Maven? Maven is an automation and management tool developed by Apache Software Foundation. It...