Is it possible to access struts2 variable in jsp scriptlet?

If I have struts2 variable like

<s:set var="test" value="%{'true'}"/>

Can I use variable "test" in JSP scriptlet?

If yes. How is it possible?

Can anyone give some idea about it?


Was it helpful?


<jsp:useBean id="test" class="java.lang.String" scope="request"/>

         test = "false";

1. outside scriptlet: <c:out value="${test}"/>   <!-- will not print anything -->

    out.println("2. in scriptlet: " + test);     // will print false

<c:set var="test" value="true" />

3. outside scriptlet: <c:out value="${test}"/>   <!-- will print true -->

    out.println("4. in scriptlet: " + test);     // will print false


You can even use the request object to get the action variable. For example, if you have a variable String userName in the action, you can use

String userName = (String) request.getAttribute("userName");


<s:set var="jspVariable" value="%{strutsVariable}"/>
<jsp:useBean id="jspVariable" type="com.example.Object" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow