今天在使用IDEA 引入JSTL标签时发现引入的标签显示为红色,不能被解析,在进行相关搜索后,根据说明,可能是IDEA的Schemas and DTDs 没有相应的配置,所以相应的进行了如下设置
重新部署项目进行测试,结果报如下错误:
HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
于是又网络搜索相关的错误信息,查找到有如下几种可能和解决方案,拿过来列出以供参考:1:原因:找不到jstl类库中的.tld文件
解决办法:
WEB/INF的lib下,除了导入jstl.jar包,还要导入standard.jar包。另外,解压standard.jar包,把.tld文件放在WEB/INF下
2:原因:JSTL的版本及相关URI路径问题。如果是JSTL1.0,uri路径为http://java.sun.com/jstl/core. JSTL1.1及之后的版本,相应uri路径为http://java.sun.com/jsp/jstl/core, 由于我使用的1.1版本,在这里的配置并没有问题。
解决过程,在第一种方式的指引下,首先在工程的配置(project setting)--->modules--->dependencies中添加standard.jar包,运行后依然报相同错误,后面发现其实standar.jar包并没有发布到项目中去,在(project setting)--->Artifacts--->Output Layout--->WEB-INF/lib中添加standard包后,再次部署项目运行,问题解决。
后面又去jstl官网看了下信息,新的JSTL版本为1.2.5,文档说明:
This version of the Standard Tag Library has the following runtime dependencies: 1. Dependencies provided by a JSP 2.1 container: - Java 1.5 or later - Servlet 2.5 or later - JSP 2.1 or later 2. Additional dependencies - The XML tag library requires Apache Xalan 2.7.1 or later
ADD DEPENDENCIES TO A WEB APPLICATION To use this distribution with your own web applications, add the following JAR files to the '/WEB-INF/lib' directory of your application: - taglibs-standard-spec-1.2.5.jar - taglibs-standard-impl-1.2.5.jar - taglibs-standard-jstlel-1.2.5.jar - xalan-2.7.1.jar - serializer-2.7.1.jar If you do not use JSTL 1.0 tags then the "taglibs-standard-jstlel" JAR may be omitted. If you do not use the XML library, then the Apache Xalan dependencies may also be omitted.于是下载相应JAR包把jstl.jar和standard.jar进行替换后部署运行依然没有问题。
总结,使用idea时,项目中配置了dependencies 后,还要把相应的jar添加到Artifacts中WEB-INF/lib目录下。这就像在myeclipse中开发,虽然添加了本地lib,但是相应jar包并没有发布到tomcat中,需要在Properties--->MyEclipse--->Deployment Assembly中进行相应添加时一样。