In this example you will learn how to use the <jsp:useBean>
. We can use the useBean
action to create a scripting variables. To define the variable name we use the id
attribute of this action. The class
attribute define the type of this variable. We can also define the scope of the variable using the scope
attribute.
As an example in the code snippet below we create a variable name now
and declare it to hold a java.util.Date
instance. And then we use a JSP expression to print out the value.
<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<title>JSP - useBean Demo</title>
</head>
<body>
<jsp:useBean id="now" class="java.util.Date"/>
Now is: <%= now %>
</body>
</html>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024