我正在使用tomcat 9,无法让JSTL标记工作。我试过了所有的解决方案,但似乎没有任何效果。为此,我即将放弃为期3个月的JSP学习。我试过的东西都不起作用。
我不知道是什么原因造成了这种情况。我不确定JSTL和web.xml的哪个版本与Tomcat 9兼容,我不使用maven。
编辑:
通过将最新的jstl-1.2.jar下载并添加到我的WEB/lib文件夹中,我终于能够解决result.jsp文件中JSTL标记的功能。因此,我能够使标准的forEach标记工作,但无法从servlet接收数组。我怀疑这与我的web.xml版本规范有关,我使用的是Tomcat 7和jstl-1.2。
在我的例子中,合适的web.xml配置是什么?
我知道这个错误
类型异常报告
消息绝对uri: http://java.sun.com/jsp/jstl/core不能在部署在此应用程序中的web.xml或jar文件中解析
描述服务器遇到的意外情况,使其无法完成请求。
异常
org.apache.jasper.JasperException: 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
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:54)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:294)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:81)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTldResourcePath(TagLibraryInfoImpl.java:251)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:122)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:435)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:493)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1450)
org.apache.jasper.compiler.Parser.parse(Parser.java:144)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:206)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:391)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:367)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:605)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:399)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:379)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:327)
javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.
我的Servlet:
package com;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class MovieList extends HttpServlet {
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException{
String [] movieList = {"movie 1","movie 2","movie 3"};
request.setAttribute("movieList", movieList);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request,response);
}
}
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>Tester</servlet-name>
<servlet-class>Tester</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Tester</servlet-name>
<url-pattern>/Tester</url-pattern>
</servlet-mapping>
</web-app>
我的观点
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<table>
<c:forEach items="${movieList}" var="movie">
<td><c:out value="${movie}"/></td>
</c:forEach>
</table>
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>nexnau</groupId>
<artifactId>makaroni</artifactId>
<version>1</version>
<packaging>war</packaging>
<name>makaroni Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
</dependencies>
<build>
<finalName>makaroni</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
,我得到了这个结果,
--这就是我使用servlet得到的
发布于 2021-06-24 23:32:36
首先,我非常怀疑您忽略了jsp文件顶部的以下内容:
<%@ page isELIgnored="false" %>
其次,我认为您需要将servlet从"doPost“更改为"doGet”。
如果它仍然不能工作,我为你做了一个演示,我希望你了解maven和git。
https://github.com/632691987/demo1.git
如果您仍然不明白,请通过以下链接给我留言:
https://github.com/632691987/demo1/issues/new
最后,我想开个玩笑:19年前,当我第一次用C语言学习"for“时,我想放弃,因为我不明白!:)
现在,我做了15年的程序员!
https://stackoverflow.com/questions/68122661
复制相似问题