Is it possible to access struts2 variable in jsp scriptlet?
If I have struts2 variable like
<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");
%>
Yes,
<s:set var="jspVariable" value="%{strutsVariable}"/>
<jsp:useBean id="jspVariable" type="com.example.Object" />
<%=jspVariable%>