When I first learned JSP, I encountered this problem. I didn't package classes when I was writing beans, that is, I didn't use the package statement. Bean compilation was correct, put the compiled class file under the WEB-INF/classes directory, then use
- <JSP: usebean id = "onlinecount" class = "mypack. onlinecount"/>
- <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
- <JSP: getproperty name = "onlinecount" property = "count"/>
The compilation result is incorrect:
- 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> your website has been published successfully </title>
- 10:
- 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> your website has been published successfully </title>
- 10:
- 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> your website has been published successfully </title>
- 10:
- 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:
- 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. Compiler (compiler. Java: 317)
- Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 295)
- Org. Apache. Jasper. compiler. compiler. Compiler (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)
After checking the information for a long time, you can find out how to solve the problem. You must put the class in the bag:
- <JSP: usebean id = "onlinecount" class = "mypack. onlinecount"/>
- <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
- <JSP: getproperty name = "onlinecount" property = "count"/>
In this way, the operation is correct.
But now I still don't understand why I have to put the class in the bag? When deploying the servlet, you don't need to put it under the package. The problem is solved now, but you still don't know why. Please let me know, thank you.