简体   繁体   中英

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. 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. I have added the jstl.jar file to my class path, the tomcat lib folder and to the WEB-INF lib folder. I also deleted Tomcat 7 because I read there might be conflicts with two Tomcat versions downloaded.

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. I had two different ones in my J2EE library folder and this whole time I kept looking into the JDK folder.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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