문제

JSP 스크립트에서 struts2 변수에 액세스 할 수 있습니까?

struts2 변수와 같은 경우

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

JSP 스크립트에서 변수 "테스트"를 사용할 수 있습니까?

경우 예. 그게 어떻게 가능해?

누구든지 그것에 대해 아이디어를 줄 수 있습니까?

감사.

도움이 되었습니까?

해결책

<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
%>

다른 팁

요청 객체를 사용하여 작업 변수를 얻을 수도 있습니다. 예를 들어 변수가있는 경우 String userName 행동에서, 당신은 사용할 수 있습니다

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

예,

<s:set var="jspVariable" value="%{strutsVariable}"/>
<jsp:useBean id="jspVariable" type="com.example.Object" />
<%=jspVariable%>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top