1

考虑:

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 10 in the jsp file: /index.jsp
Mybean cannot be resolved to a type
7: <title></title>
8: </head>
9: <body>
10: <jsp:useBean id="bean1" class="Mybean"/>
11: <jsp:setProperty name="bean1"
12:                     property="name"
13:                     value="bean1" />



An error occurred at line: 17 in the jsp file: /index.jsp
Mybean cannot be resolved to a type
14:     <jsp:setProperty name="bean1"
15:                     property="id"
16:                     value="1" />
17:                     <jsp:getProperty name="bean1" property="name" />
18:                         <jsp:getProperty name="bean1" property="id" />
19:
20: </body>

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

我制作了一个带有 Mybean 名称的 Java 类。我正在使用 JSP 来设置属性和获取属性。我收到一个我无法解决的错误。

4

1 回答 1

2

来自JSP 规范

从 JSP 2.0 开始,引用未命名(也称为默认)包中的任何类都是非法的。

所以你的bean必须有一个包声明:

package foo;
public class MyBean {}

包必须反映在应用程序结构中;例如:

WEB-INF/classes/foo/MyBean.class

必须在标签中使用限定名称:

<jsp:useBean id="bean1" class="foo.MyBean"/>
于 2013-01-21T11:13:19.867 回答