【问题标题】:JSP compiled but now has several errors?JSP编译但现在有几个错误?
【发布时间】:2014-09-19 01:32:31
【问题描述】:

我在 github 上有一个 JSP 和 Servlet 项目 - https://github.com/double-whammy/affablebean.git。这段代码至少在我的旧电脑上正确编译。当我将它导入我的新计算机时,它显示了很多奇怪的编译错误。我将向您展示一些代码和错误。请帮我纠正这个问题。

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/affablebean.css">
<title>The Affable Bean</title>
</head>
<body>

    <sql:query var="categories" dataSource="jdbc/affablebean">
    SELECT * FROM category
    </sql:query>

    <sql:query var="selectedCategory" dataSource="jdbc/affablebean">
    SELECT name FROM category WHERE id = ?
    <sql:param value="${pageContext.request.queryString}" />
    </sql:query>

    <sql:query var="categoryProducts" dataSource="jdbc/affablebean">
    SELECT * FROM product WHERE category_id = ?
    <sql:param value="${pageContext.request.queryString}" />
    </sql:query>

    <div id="categoryLeftColumn">

        <c:forEach var="category" items="${categories.rows}">

            <c:choose>
                <c:when test="${category.id == pageContext.request.queryString}">
                    <div class="categoryButton" id="selectedCategory">
                        <span class="categoryText"> ${category.name} </span>
                    </div>
                </c:when>
                <c:otherwise>
                    <a href="category?${category.id}" class="categoryButton">
                        <div class="categoryText">${category.name}</div>
                    </a>
                </c:otherwise>
            </c:choose>

        </c:forEach>

    </div>
</body>
</html>

错误是:

线&lt;sql:param value="${pageContext.request.queryString}" /&gt;

Multiple annotations found at this line:
    - java.io.IOException cannot be resolved to a type
    - No exception of type ServletException can be thrown; an exception type must be a subclass of 
     Throwable
    - The method getQueryString() from the type HttpServletRequest refers to the missing type String
    - String cannot be resolved to a type

线&lt;sql:query var="categoryProducts" dataSource="jdbc/affablebean"&gt;

No exception of type JspException can be thrown; an exception type must be a subclass of Throwable

线&lt;c:forEach var="category" items="${categories.rows}"&gt;

Multiple annotations found at this line:
    - java.util.Map cannot be resolved 
     to a type

【问题讨论】:

  • 我看到在项目属性、订单和导出选项卡中,JDK 上有一个叉号,它表示 jre 未绑定。进一步调查。

标签: java jsp jakarta-ee


【解决方案1】:

Google 这个错误The method getQueryString() from the type HttpServletRequest refers to the missing type String 没有getQueryString()SO post 暗示这可能是项目默认 jre 的问题(如果您正在做 Java 企业项目,实际上是 jdk)。

在 Eclipse 中,您的项目 > 右键单击​​ > 订购和导出选项卡。 JRE 系统库旁边应该有一个红叉,并且状态是未绑定的。 Another SO post 建议您为此更改/修复默认的 jre 或 jdk。

在 Eclipse 中,窗口 > 首选项。删除所有旧的 Jres 或 Jdk,然后再次删除一个 jdk。添加>标准VM>下一步>找到你安装jdk等的文件夹。>完成。

返回到您的项目属性。 JRE系统库旁边应该有错误。选择它并删除它。然后,添加库>添加上一步中刚刚设置的Jre/jdk。

重建并清理您的项目。问题解决了。

【讨论】:

    猜你喜欢
    • 2021-05-21
    • 1970-01-01
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-17
    • 2015-07-21
    相关资源
    最近更新 更多