簡體   English   中英

JSTL在嘗試訪問bean時給出錯誤

[英]JSTL giving Error when trying to access bean

我在這里待了一個多星期。 嘗試訪問bean時出現錯誤。 我的錯誤是:

The value for the useBean class attribute beans.Bean is invalid.
                 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41) 

這是代碼:

package beans;

public class Bean {

private String message = "This is from the bean";

public Bean(){

}

public String getMessage(){

    return message;
}

}

<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import = "beans.Bean" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<!--Location of Css file-->
<link rel="stylesheet" href="css/format.css" type="text/css"  />

<title>Insert title here</title>
</head>
<body>

<div id="intro">
<table border="1">
<tr>
    <th>1</th>  
    <th>2</th>
    <th>3</th>
</tr>       
<tr>
    <td>One</td>
    <td>Two</td>
    <td>Three</td>
</tr>
</table>
</div>

<jsp:useBean id="message" class="beans.Bean" scope="session" />

<p>From the bean: <c:out value="${message.getMessage()}" /></p>

</body>
</html>

我正在使用Tomcat 8,而我的JDK也是8。 我已經將jstl.jar文件添加到我的類路徑,tomcat lib文件夾和WEB-INF lib文件夾中。 我還刪除了Tomcat 7,因為我讀到與下載的兩個Tomcat版本可能存在沖突。

請,任何建議將不勝感激。

我已經找到了解決我自己的問題的方法:

我的JSTL.jar文件發生沖突。 我的J2EE庫文件夾中有兩個不同的文件夾,而整個過程中,我一直在關注JDK文件夾。

嘗試使用message.message而不是message.getMessage()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM