今天用jstl+el从session域中获取属性,遇到了问题
org.apache.jasper.JasperException: <h3>Validation error messages from TagLibraryValidator for [c] in [/login.jsp]</h3><p>2: Illegal scope attribute without var in "c:if" tag.</p><p>19: Illegal scope attribute without var in "c:if" tag.</p>
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:55)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:294)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:81)
org.apache.jasper.compiler.Validator.validateXmlView(Validator.java:1917)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1863)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:224)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:385)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:362)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:346)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:603)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
刷新页面时有时候报错,有时候还不报错,有点懵,一直用的标签怎么就报错了?
根据错误提示信息查找源码
<c:if test="${count>=1&&count<3}" scope="session">
<c:out value="<span>账号或密码错误</span><br/>" escapeXml="false"></c:out>
<c:out value="<span>剩余登陆次数:${sessionScope.count}</span>" escapeXml="false"></c:out>
</c:if>
其中:count属性已放在session域中
想了下,可能scope不是表示count所在域的,if标签还有一个属性是var,是用来存储test的结果值,那么scope是不是用于表示var的作用域的?
更改代码
<c:if test="${sessionScope.count>=1&&sessionScope.count<3}">
<c:out value="<span>账号或密码错误</span><br/>" escapeXml="false"></c:out>
<c:out value="<span>剩余登陆次数:${sessionScope.count}</span>" escapeXml="false"></c:out>
</c:if>
错误解决!
原文地址:https://www.cnblogs.com/mlr-wjy/p/12048475.html
时间: 2024-11-09 00:47:10