JSP: Class Attribute of usebean

Source: Internet
Author: User
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
  1. <JSP: usebean id = "onlinecount" class = "mypack. onlinecount"/>
  2. <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
  3. <JSP: getproperty name = "onlinecount" property = "count"/>

The compilation result is incorrect:

  1. Org. Apache. Jasper. jasperexception: Unable to compile class for JSP:
  2. An error occurred at line: 12 in the JSP file:/index. jsp
  3. Onlinecount cannot be resolved to a Type
  4. 9: <title> your website has been published successfully </title>
  5. 10:
  6. 11: <body>
  7. 12: <JSP: usebean id = "onlinecount" class = "onlinecount"/>
  8. 13: <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
  9. 14: <JSP: getproperty name = "onlinecount" property = "count"/>
  10. 15: </body>
  11. An error occurred at line: 12 in the JSP file:/index. jsp
  12. Onlinecount cannot be resolved to a Type
  13. 9: <title> your website has been published successfully </title>
  14. 10:
  15. 11: <body>
  16. 12: <JSP: usebean id = "onlinecount" class = "onlinecount"/>
  17. 13: <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
  18. 14: <JSP: getproperty name = "onlinecount" property = "count"/>
  19. 15: </body>
  20. An error occurred at line: 12 in the JSP file:/index. jsp
  21. Onlinecount cannot be resolved to a Type
  22. 9: <title> your website has been published successfully </title>
  23. 10:
  24. 11: <body>
  25. 12: <JSP: usebean id = "onlinecount" class = "onlinecount"/>
  26. 13: <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
  27. 14: <JSP: getproperty name = "onlinecount" property = "count"/>
  28. 15: </body>
  29. An error occurred at line: 14 in the JSP file:/index. jsp
  30. Onlinecount cannot be resolved to a Type
  31. 11: <body>
  32. 12: <JSP: usebean id = "onlinecount" class = "onlinecount"/>
  33. 13: <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
  34. 14: <JSP: getproperty name = "onlinecount" property = "count"/>
  35. 15: </body>
  36. 16:
  37. Stacktrace:
  38. Org. Apache. Jasper. compiler. defaulterrorhandler. javacerror (defaulterrorhandler. Java: 92)
  39. Org. Apache. Jasper. compiler. errordispatcher. javacerror (errordispatcher. Java: 330)
  40. Org. Apache. Jasper. compiler. jdtcompiler. generateclass (jdtcompiler. Java: 423)
  41. Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 317)
  42. Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 295)
  43. Org. Apache. Jasper. compiler. compiler. Compiler (compiler. Java: 282)
  44. Org. Apache. Jasper. jspcompilationcontext. Compile (jspcompilationcontext. Java: 586)
  45. Org. Apache. Jasper. servlet. jspservletwrapper. Service (jspservletwrapper. Java: 317)
  46. Org. Apache. Jasper. servlet. jspservlet. servicejspfile (jspservlet. Java: 342)
  47. Org. Apache. Jasper. servlet. jspservlet. Service (jspservlet. Java: 267)
  48. 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:

  1. <JSP: usebean id = "onlinecount" class = "mypack. onlinecount"/>
  2. <JSP: setproperty name = "onlinecount" property = "count" value = "8"/>
  3. <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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.