JSP
JSP Database Connection: Select, Insert, Update & Delete Example
The database is used for storing various types of data which are huge and has storing capacity in...
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
The database is used for storing various types of data which are huge and has storing capacity in...
What are JSP Directives? JSP directives are the messages to JSP container. They provide global...
What is JSP LifeCycle? JSP Life Cycle is defined as translation of JSP Page into servlet as a JSP...
JSP actions which use constructs in XML syntax to control the behavior of the servlet engine. We...
What is MVC? MVC is an architecture that separates business logic, presentation and data. In MVC, M...
Debugging is the process to trace the error in the application. It is not very easy to trace bugs...