在其他情况下包含一个JSP文件 [英] include a JSP file in another with cases
问题描述
我如何在另一个具有IF结构的JSP中包含一个JSP页面:
How can i include a JSP page in another JSP with the IF structure:
我可以在JSP文件中使用这部分代码吗?
Can i use this part of code in a JSP file:
<%
UtilisateurAction useraction = new UtilisateurAction();
String statut = useraction.Connect();
//System.out.println(statut);
if(statut=="ADMIN"){
%> <%@ include file="menu.jsp"%>
<%}
else {if(statut=="USER"){%>
<%@ include file="menu.jsp"%>
<%}} %>
推荐答案
<%@ include file="menu.jsp"%>
是静态包含,因此无论条件如何,它都将包含menu.jsp
的内容.但是只有在条件为真时才会执行.
The <%@ include file="menu.jsp"%>
is static include, so it will include contents of the menu.jsp
no matter of the condition. But it will be executed only if the condition is true.
<jsp:include page="menu.jsp" flush="true"/>
是动态包含,因此,只有在满足条件的情况下,才会真正调用menu.jsp
页.但另一方面,menu.jsp
必须是整页,而不是页面片段,并且不能使用在父"页面中定义的变量.
The <jsp:include page="menu.jsp" flush="true"/>
is dynamic include, so, the menu.jsp
page will actually be called only if the condition is satisfied. But from the other side menu.jsp
must be a full page, not a page fragment, and cannot use variables defined in the 'parent' page.
所以,这实际上取决于您要实现的目标.
So, it really depends on what you want to achieve.
并且正如Marco所建议的那样,您应该使用"ADMIN".equals(statut)
而不是==
.
And as Marco suggested, you should use "ADMIN".equals(statut)
instead of ==
.
这篇关于在其他情况下包含一个JSP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!