我试图看看Javabeans是如何是如何工作的,所以我创建了一个简单的JSP项目,它具有InfoRet.java
(Javabean) 和一个 JSP 文件来从 bean 中检索值。
这是代码:
public class InfoRet implements java.io.Serializable {
private static final long serialVersionUID = 1L;
private String name;
private int age;
public InfoRet() {
}
public String getname() {
return this.name;
}
public int getage() {
return this.age;
}
public void setname(String name) {
this.name = name;
}
public void setage(int age) {
this.age = age;
}
}
这是 JSP 文件:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<!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=ISO-8859-1">
<title>Insert title here</title>
<jsp:useBean id="obj" class="InfoRet" scope="session"></jsp:useBean>
</head>
<body>
<jsp:setProperty name="obj" property="name" value="harshal" />
<jsp:setProperty name="obj" property="age" value="323" />
<jsp:getProperty name="obj" property="name" />
<br/>
<jsp:getProperty name="obj" property="age" />
</body>
</html>
错误是:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
5: <head>
6: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7: <title>Insert title here</title>
8: <jsp:useBean id="obj" class="InfoRet" scope="session" ></jsp:useBean>
9: </head>
10: <body>
11: <jsp:setProperty name="obj" property="name" value="harshal"/>
An error occurred at line: 8 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
5: <head>
6: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7: <title>Insert title here</title>
8: <jsp:useBean id="obj" class="InfoRet" scope="session" ></jsp:useBean>
9: </head>
10: <body>
11: <jsp:setProperty name="obj" property="name" value="harshal"/>
An error occurred at line: 8 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
5: <head>
6: <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7: <title>Insert title here</title>
8: <jsp:useBean id="obj" class="InfoRet" scope="session" ></jsp:useBean>
9: </head>
10: <body>
11: <jsp:setProperty name="obj" property="name" value="harshal"/>
An error occurred at line: 14 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
11: <jsp:setProperty name="obj" property="name" value="harshal"/>
12: <jsp:setProperty name="obj" property="age" value="323" />
13:
14: <jsp:getProperty name="obj" property="name"/>
15: <br/>
16: <jsp:getProperty name="obj" property="age"/>
17: </body>
An error occurred at line: 14 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
11: <jsp:setProperty name="obj" property="name" value="harshal"/>
12: <jsp:setProperty name="obj" property="age" value="323" />
13:
14: <jsp:getProperty name="obj" property="name"/>
15: <br/>
16: <jsp:getProperty name="obj" property="age"/>
17: </body>
An error occurred at line: 16 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
13:
14: <jsp:getProperty name="obj" property="name"/>
15: <br/>
16: <jsp:getProperty name="obj" property="age"/>
17: </body>
18: </html>
An error occurred at line: 16 in the jsp file: /indexs.jsp
InfoRet cannot be resolved to a type
13:
14: <jsp:getProperty name="obj" property="name"/>
15: <br/>
16: <jsp:getProperty name="obj" property="age"/>
17: </body>
18: </html>
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
所以我想知道上面的代码有什么问题。