I think I'm doing something horrible wrong here.
I've never used NetBeans before, nor have I ever done anything with JavaServer before, though I've programmed in Java. In netBeans, in a web project, I created a package called DonationCalc, with a file DonationCalc.java, containing my bean. In a jsp file, I have the following:
<%@page import="DonationCalc.*" %> [...] <jsp:useBean id="Calc" class="DonationCalc" />
However, I'm getting "string://开发者_如何学Python/DonationCalc_jsp.java:6: package DonationCalc does not exist"
I've been reading elsewhere about classes going under WEB-INF/Classes, but I have no such folder, and NetBeans insists any new packages be put under "Source Packages".
What do I need to add to help my .jsp file find the bean? A directory path of some sort? Or should I be putting things elsewhere to begin with?
ETA: Apparently the issue is that it was configured for glassfish instead of tomcat. Creating a new project under tomcat, however, has created such a clusterfuck of problems that I have sworn off all forms of java, including the island nation and all caffeinated beverages.
You don't need the @page import
here since that only imports into the scriptlet scope, not into the taglib scope. You don't want to use scriptlets, so forget about it at all. In the jsp:useBean class
you need to specify the full qualified classname, thus including the package name.
<jsp:useBean id="calc" class="com.example.DonationCalc" />
By the way:
I've been reading elsewhere about classes going under WEB-INF/Classes, but I have no such folder, and NetBeans insists any new packages be put under "Source Packages".
That's true. IDE's like Netbeans and Eclipse automatically builds and compiles the source files into the right locations. You don't need to worry about this. This is however mandatory to know when you want to understand how it works "under the hoods" and/or you want to (be able) to build using command console tools instead of an IDE.
精彩评论