是否可以在jsp scriptlet中访问struts2变量?

Is it possible to access struts2 variable in jsp scriptlet?

是否可以在jsp scriptlet中访问struts2变量?

如果我有struts2变量像

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

我可以在JSP脚本中使用变量" test"吗?

如是。 这怎么可能?

任何人都可以提出一些想法吗?

谢谢。


您甚至可以使用request对象获取action变量。 例如,如果操作中有变量String userName,则可以使用

1
2
3
<%
String userName = (String) request.getAttribute("userName");
%>


是,

1
2
3
<s:set var="jspVariable" value="%{strutsVariable}"/>
<jsp:useBean id="jspVariable" type="com.example.Object" />
<%=jspVariable%>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<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
%>