Priya
Priya

Reputation: 13

Assign variable in JSP file to Java String

I have this variable ${baseURL} which is set like so

<c:set var="baseURL" value="${fn:replace(pageContext.request.requestURL, 
  pageContext.request.requestURI, pageContext.request.contextPath)}" />                 

I need to assign it to a Java String or pass it into a Java function within the same jsp file.

Upvotes: 0

Views: 1343

Answers (1)

Bashir
Bashir

Reputation: 2051

You can assign a JSTL variable to a JAVA variable by getting its value using pageContext.getAttribute() method as follow:

<% Strig s = (String)pageContext.getAttribute("baseURL"); %>

Upvotes: 1

Related Questions