刚学jsp就遇到了这个问题,写bean的时候想不要弄那么复杂,就没有将类打包,即没有使用package语句,bean编译的时候是正确的,就把编译后的class文件放到了WEB-INF/classes目录下,接下来用
结果编译错误了:
查了好久的资料才知道了要怎么解决,必须要把类放在包里:
这样才运行正确了。
但是我到现在还是不明白为什么非要把类放在包里呢?在部署servlet时却可以不用放在包下面,问题现在是解决了,可是还是不知道为什么,还望知道的朋友告诉我一声,谢谢。
- <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" />
但是我到现在还是不明白为什么非要把类放在包里呢?在部署servlet时却可以不用放在包下面,问题现在是解决了,可是还是不知道为什么,还望知道的朋友告诉我一声,谢谢。