首页 > 代码库 > JSP异常之org.apache.jasper.JasperException(转)
JSP异常之org.apache.jasper.JasperException(转)
According to TLD or attribute directive in tag file, attribute items does not accep t any expressions
- 严重: Servlet.service() for servlet jsp threw exception
- org.apache.jasper.JasperException: /selectorTagtest.jsp(26,8) According to TLD or attribute directive in tag file, attribute items does not accep
- t any expressions
- at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
- at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
- at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
- at org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1172)
- at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:819)
- at org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1512)
- at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
- at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2393)
- at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2399)
- at org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
- at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2343)
- at org.apache.jasper.compiler.Validator.validate(Validator.java:1737)
- at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:165)
- at org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
- at org.apache.jasper.compiler.Compiler.compile(Compiler.java:294)
- at org.apache.jasper.compiler.Compiler.compile(Compiler.java:281)
- at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
- at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
- at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
- at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:413)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
- at java.lang.Thread.run(Thread.java:595)
解决方法:
把
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改为:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
另一篇描述比较透彻的分析如下:
环境: win2003 tomcat 5.5 JDK1.6上
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
</web-app>
jsp代码:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
1+2+3 = ${1+2+3} <br>
1+2+3 = <c:out value="http://www.mamicode.com/6" /> <br>
此时执行没有任何问题。
1+2+3 = <c:out value="http://www.mamicode.com/${1+2+3}" />执行时就会出现:
According to TLD or attribute directive in tag file, attribute value does not accept any expressions
昨天少了一个jsp,所以一直出现问题。
代码
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
写成
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
今天再试。发现JSTL1.1可以用。但是用JSTL1.0时,出现问题。
就是把JSTL1.1的库放到/WEB-INF/lib/ 下。
刚开始我是netbeans 5.5.1中的JSTL库拷贝出来发现可以用。后来用jstl1.1.2的库,也是可以用。
总结:
JSTL1.1的库 在JSP2.0(Servlet 2.4)及以后(推荐用JSTL1.1及以上)用:
代码
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
</web-app>
在 Servlet2.3及以前,
代码
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
比2.4以后版本少了jsp
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
</web-app>
在Servlet2.3中最好用JSTL1.0,如果用JSTL1.1,请加上
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<taglib>
<taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
</web-app>
把tld目录下的c.tld拷贝到/WEB-INF?下。
找到官方下载地址:
http://jakarta.apache.org/site/downloads/downloads_taglibs.html
选择 Standard 1.0 Taglib 和Standard 1.1 Taglib 可以下载jstl1.0和jstl1.1版本。
According to TLD or attribute directive in tag file, attribute page does not accept any expressions
说的是对应tag的属性不支持表达式传入。解决的办法是,在tld文件的相应tag的相应属性中加上rtexprvalue属性并设置为true,比如:
<tag>
<name>CustomTag</name>
……
<attribute>
<name>AttName</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
网上说这个和Tomcat的版本也有关系(5.x),我用的恰好是5.0.27,不过这个没有证实过。
应用部署运行的时候出现JSP异常, 发生在使用JSTL库的时候: According to TLD or attribute directive in tag file, attribute value does not accept any expressions, 可能是因为使用了JSP2.0版本, 同时又没有使用JSTL core库的备用版本(RT库), 以下有两种处理方法:
1. 修改web.xml.
<web-app
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
改为2.3版本的
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
2. 使用JSTL core RT库
JSTL core库的有两种taglib伪指令, 其中RT库即是依赖于JSP传统的请求时属性值, 而不是依赖于EL来实现(称为EL库.JSP2.0将支持EL)
JSP中使用<%@ taglib uri=http://java.sun.com/jstl/core prefix="c"%>在2.3版本都可以,在2.4就不行了, 难道是版本不兼容吗?
只要将
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改为
<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>
就没有问题了
转载自:http://www.cnblogs.com/fish-king/archive/2013/01/16/2862686.html
JSP异常之org.apache.jasper.JasperException(转)