您的位置:首页 > Web前端 > JavaScript

jsp:useBean 不能编译成class或者没有class这个属性

2013-01-25 09:04 267 查看
刚学jsp就遇到了这个问题,写bean的时候想不要弄那么复杂,就没有将类打包,即没有使用package语句,bean编译的时候是正确的,就把编译后的class文件放到了WEB-INF/classes目录下,接下来用

<jsp:useBean id="onlineCount" class="mypack.OnlineCount" />
<jsp:setProperty name="onlineCount" property="count" value="8" />
<jsp:getProperty name="onlineCount" property="count" />

结果编译错误了:

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

An error occurred at line: 12 in the jsp file: /index.jsp
OnlineCount cannot be resolved to a type
9: <title>鎴戠殑缃戠珯</title>
10: </head>
11: <body>
12: <jsp:useBean id="onlineCount" class="OnlineCount" />
13: <jsp:setProperty name="onlineCount" property="count" value="8" />
14: <jsp:getProperty name="onlineCount" property="count" />
15: </body>

An error occurred at line: 12 in the jsp file: /index.jsp
OnlineCount cannot be resolved to a type
9: <title>鎴戠殑缃戠珯</title>
10: </head>
11: <body>
12: <jsp:useBean id="onlineCount" class="OnlineCount" />
13: <jsp:setProperty name="onlineCount" property="count" value="8" />
14: <jsp:getProperty name="onlineCount" property="count" />
15: </body>

An error occurred at line: 12 in the jsp file: /index.jsp
OnlineCount cannot be resolved to a type
9: <title>鎴戠殑缃戠珯</title>
10: </head>
11: <body>
12: <jsp:useBean id="onlineCount" class="OnlineCount" />
13: <jsp:setProperty name="onlineCount" property="count" value="8" />
14: <jsp:getProperty name="onlineCount" property="count" />
15: </body>

An error occurred at line: 14 in the jsp file: /index.jsp
OnlineCount cannot be resolved to a type
11: <body>
12: <jsp:useBean id="onlineCount" class="OnlineCount" />
13: <jsp:setProperty name="onlineCount" property="count" value="8" />
14: <jsp:getProperty name="onlineCount" property="count" />
15: </body>
16: </html>

Stacktrace:
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:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
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)

查了好久的资料才知道了要怎么解决,必须要把类放在包里:

<jsp:useBean id="onlineCount" class="mypack.OnlineCount" />
<jsp:setProperty name="onlineCount" property="count" value="8" />
<jsp:getProperty name="onlineCount" property="count" />

这样才运行正确了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐