Reputation:
Consider:
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)
I have made a Java class with Mybean name. I am making use of JSP to set attributes and get attributes. I am getting an error which I am not able to resolve.
Upvotes: 1
Views: 1999
Reputation: 108879
From the JSP specification:
As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a. default) package.
So your bean must have a package declaration:
package foo;
public class MyBean {}
The package must be reflected in the application structure; e.g:
WEB-INF/classes/foo/MyBean.class
The qualified name must be used in the tag:
<jsp:useBean id="bean1" class="foo.MyBean"/>
Upvotes: 2