Is it possible to access struts2 variable in jsp scriptlet?

后端 未结 3 2028
盖世英雄少女心
盖世英雄少女心 2020-12-30 18:08

Is it possible to access struts2 variable in jsp scriptlet?

If I have struts2 variable like


         


        
相关标签:
3条回答
  • 2020-12-30 18:39
    <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
    %>
    
    0 讨论(0)
  • 2020-12-30 18:42

    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");
    %>
    
    0 讨论(0)
  • 2020-12-30 18:50

    Yes,

    <s:set var="jspVariable" value="%{strutsVariable}"/>
    <jsp:useBean id="jspVariable" type="com.example.Object" />
    <%=jspVariable%>
    
    0 讨论(0)
提交回复
热议问题