JSTL在尝试访问bean时给出错误

时间:2015-01-28 08:57:38

标签: java tomcat

我已经待了一个多星期了。我尝试访问我的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版本存在冲突。

请,任何建议将不胜感激。

2 个答案:

答案 0 :(得分:1)

我找到了解决自己问题的方法:

与我的JSTL.jar文件存在冲突。我的J2EE库文件夹中有两个不同的文件,这一直是我一直在查看JDK文件夹。

答案 1 :(得分:0)

尝试使用message.message而不是message.getMessage()

相关问题