Pregunta

¿Es posible acceder a la variable de struts2 en scriptlet JSP?

Si he struts2 variable, como

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

¿Puedo utilizar "prueba" variable en JSP scriplet?

En caso afirmativo. ¿Cómo es posible?

Puede alguien dar alguna idea al respecto?

Gracias.

¿Fue útil?

Solución

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

Otros consejos

Usted puede incluso utilizar el objeto de solicitud para obtener la variable de acción. Por ejemplo, si tiene un String userName variable en la acción, puede utilizar

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

Sí,

<s:set var="jspVariable" value="%{strutsVariable}"/>
<jsp:useBean id="jspVariable" type="com.example.Object" />
<%=jspVariable%>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top