在我的JSP文件中集成<c:if> </c:if>

时间:2014-08-09 14:17:26

标签: java jsp jstl

我要整合我的JSP文件,这是我写的代码:

<%  UtilisateurAction useraction = new UtilisateurAction();
    String statut = useraction.Connect(); %>

<c:if test=<%"ADMIN".equals(statut);%>>

<%@ include file="../menu/menu.jsp"%>
</c:if> 


<c:if test=<% "SECR".equals(statut);%>>

<%@ include file="../menu/menuother.jsp"%>
</c:if>

它不起作用,我不知道为什么我在控制台中出现此错误:

  

引用符号预期在   org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)     在   org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:443)     在   org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)     在org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:222)     在org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:162)     在org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:153)     在org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1236)     在org.apache.jasper.compiler.Parser.parseElements(Parser.java:1452)     在org.apache.jasper.compiler.Parser.parse(Parser.java:138)at   org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)     在   org.apache.jasper.compiler.ParserController.parse(ParserController.java:102)     在   org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)     在org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)at   org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)at   org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)at   org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:657)     在   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)     在   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)     在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)     在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)     在   org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)     在   org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)     在   org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)     在   org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)     在   org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)at at   org.apache.struts2.rest.RestActionInvocation.executeResult(RestActionInvocation.java:241)     在   org.apache.struts2.rest.RestActionInvocation.processResult(RestActionInvocation.java:198)     在   org.apache.struts2.rest.RestActionInvocation.invoke(RestActionInvocation.java:146)     在   com.opensymphony.xwork2.DefaultActionProxy.execute(DefaultActionProxy.java:147)     在   org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)     在   org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)     在   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)     在   org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:607)     在   org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:313)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:603)     在java.lang.Thread.run(Thread.java:722)

1 个答案:

答案 0 :(得分:0)

修改:忘记了test=

中的c:if

要使用<c:if>,您必须拥有范围变量。当前请求的属性,应用程序上下文的会话各自的范围是请求,会话和应用程序。

您可以轻松地将变量放在页面上下文中(仅对当前jsp有效,而@include包含的其他内容有效,但<jsp:include>不包含):

<%
...
String statut = useraction.Connect();
pageContext.setAttribute("statut", statut);
%>
<c:if test="${statut == 'ADMIN'}">
...
</c:if>