Reputation: 93
I would like to know if I can add custom variables to the context of a JSP page.
For example, you can use out
instead of System.out
, is this also possible with own variables so I can use something like myApplication.getVersion()
?
Or is there another library for doing this?
Upvotes: 3
Views: 85
Reputation: 49656
Yes, it is possible with JSTL tag c:set
.
<c:set var="application" scope="session" value="${requestScope.myApplication}"/>
Then you could call any method like ${application.getVersion()}
.
<jsp:useBean id="name" scope="request" type="your.package.Class"/>
Alternatively, you may use bean definition and refer to the object as ${name}
.
Upvotes: 1