【问题标题】:How to make this jsp page work on Tomcat with eclipse? [duplicate]如何使这个jsp页面在带有eclipse的Tomcat上工作? [复制]
【发布时间】:2020-02-14 09:55:30
【问题描述】:

JSP 页面:

<%@ page language="java" contentType="text/html; utf-8"
    pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="sv" dir="ltr">
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>

<c:forEach begin="1" end="5" var="current">
    <c:out value="${current}"/>
    <p>${current}</p>
</c:forEach>

</body>
</html>

Maven POM 文件:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>GroupName</groupId>
  <artifactId>AppName</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.19</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.14</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
  </dependencies>
  <build>
    <finalName>Whatever</finalName>
  </build>
</project>

而不是输出 1 2 3 4 5 我得到 ${current} ${current} ${current} ${current} ${current}

我在 Eclipse 中编写代码,并使用 maven 进行依赖。我在本地 Tomcat 服务器中运行代码。 可能是很少的背景信息,但它很难,因为 Eclipse + Tomcat + Maven = 100000 种做事方式,奇怪的怪癖,配置等。希望它可能是显而易见的。

【问题讨论】:

    标签: maven jstl


    【解决方案1】:

    尝试这些依赖项:

       <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.1.0</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>javax.servlet.jsp-api</artifactId>
          <version>2.3.1</version>
          <scope>provided</scope>
        </dependency>
    
        <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
          <version>1.2</version>
        </dependency>
    

    如果这不起作用,请右键单击项目并进入属性 -> 项目方面。

    并确保 Dynamic Web Module 是 3.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多