考虑:
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来设置属性和获取属性。我收到一个我无法解决的错误。
答案 0 :(得分:1)
从JSP 2.0开始,引用未命名(a.k.a. default)包中的任何类是非法的。
所以你的bean必须有一个包声明:
package foo;
public class MyBean {}
包必须反映在应用程序结构中; e.g:
WEB-INF/classes/foo/MyBean.class
必须在标记中使用限定名称:
<jsp:useBean id="bean1" class="foo.MyBean"/>