简体   繁体   English

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

[英]JSTL giving Error when trying to access bean

I have been at this for over a week. 我在这里待了一个多星期。 I am getting an error when I try to access my bean. 尝试访问bean时出现错误。 My error reads: 我的错误是:

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

Here is the the code: 这是代码:

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>

I am using Tomcat 8 and my JDK is 8 as well. 我正在使用Tomcat 8,而我的JDK也是8。 I have added the jstl.jar file to my class path, the tomcat lib folder and to the WEB-INF lib folder. 我已经将jstl.jar文件添加到我的类路径,tomcat lib文件夹和WEB-INF lib文件夹中。 I also deleted Tomcat 7 because I read there might be conflicts with two Tomcat versions downloaded. 我还删除了Tomcat 7,因为我读到与下载的两个Tomcat版本可能存在冲突。

Please, any advice would be greatly appreciated. 请,任何建议将不胜感激。

I have found a solution to my own probelm: 我已经找到了解决我自己的问题的方法:

There was a conflict with my JSTL.jar files. 我的JSTL.jar文件发生冲突。 I had two different ones in my J2EE library folder and this whole time I kept looking into the JDK folder. 我的J2EE库文件夹中有两个不同的文件夹,而整个过程中,我一直在关注JDK文件夹。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM