E 'possibile accedere alle variabili Struts2 in scriptlet jsp?
Domanda
E 'possibile accedere alla variabile Struts2 in scriptlet jsp?
Se ho Struts2 variabile come
<s:set var="test" value="%{'true'}"/>
Posso usare "test" variabile in JSP scriptlet?
Se sì. Come è possibile?
Qualcuno può dare qualche idea in proposito?
Grazie.
Soluzione
<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
%>
Altri suggerimenti
È anche possibile utilizzare l'oggetto di richiesta per ottenere la variabile di azione. Ad esempio, se si dispone di un String userName
variabile nell'azione, è possibile utilizzare
<%
String userName = (String) request.getAttribute("userName");
%>
Si,
<s:set var="jspVariable" value="%{strutsVariable}"/>
<jsp:useBean id="jspVariable" type="com.example.Object" />
<%=jspVariable%>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow