- This topic has 13 replies, 3 voices, and was last updated 19 years, 6 months ago by
Scott Anderson.
-
AuthorPosts
-
wsheafferMemberThis is probably a pretty simple problem but I can’t seem to find a solution for it. I have created a simple JSP application, the directory structure is correct but my application cannot seem to locate the Java class which is in the src directory. I get the red cross marks and it says the class is undefined.
Is there a special pathing I must do when I add a class to the project? I am only using it to store form data.
Thanks in advance for any help.
🙁
Scott AndersonParticipantI have created a simple JSP application, the directory structure is correct but my application cannot seem to locate the Java class which is in the src directory.
It’s not just the directory structure that needs to be correct. Is it a MyEclipse Web Project, or just a plain Java project? If it’s a MyEclipse Web Project, is your workspace set to build automatically (Project > Build Automatically). For information on getting a sample web project running quickly, please see our web project quickstart in the documentation section here: http://www.myeclipseide.com/images/tutorials/quickstarts/webprojects/
wsheafferMemberThanks for your reply. Yes the automatic build is on, I checked it first thing. Yes the tutorial is great and I have got through several of them from start to finish.
This problem however is rather vexing for me and I am relatively confident that there is a simple solution which I am not aware of.
The application is simple, an index.jsp calls a html form, GetName.html which in turn uses NextPage.jsp and SaveName.jsp to store the data from the form in the Java class UserData.java.
There are no syntax errors that I can find and following JSP generates and error:
<%@ page language=”java” import=”java.util.*” %>
<jsp:useBean id=”user” class=”UserData” scope=”session”/>
<HTML>
<BODY>
You entered<BR>
Name: <%= user.getUsername() %><BR>
Email: <%= user.getEmail() %><BR>
Age: <%= user.getAge() %><BR>
</BODY>
</HTML>It says that it cannot resolve the class “UserData”. Yet UserData.java is located in the “src” directory as per the design.
I am running
Win XP Pro
java 1.4.2_08
Eclipse
MyEclipseAny further suggestions would be greatly appreciated.
Scott AndersonParticipantI believe you’re going to need an import statement for UserData, just like the one you have for java.util.*. Otherwise, the generated Java doesn’t know what package to look in for it.
wsheafferMemberThank you for your reply.
I took my project out of the MyEclipse hierarchy and simply wrote it and deployed it by hand to Tomcat.
It works fine. I then downloaded a similar project with the sample configuration and deployed the associated “war” file to Tomcat. It expanded the war and the application ran fine.
The issue, it seems is that I do not know to configure either:
1. An environmental variable, such as a classpath
2. A project setting within the environment
3. An installation setting
This problem only occurs in web apps and the MyEclipse IDE properly identifys that the Java Class which is part of the project, and properly in the src directory cannot be seen and therefore I get an error which states that the class is not identified.
On jarring up and moving the MyEclipse directory structure to Tomcat, the application terminates when I try to instaniate an object of the Java Class which is clearly a part of my project.
If you can answer this query I would be grateful. I have spent about 10 hours now with your documentation to no avail.
Thank you in advance.
Scott AndersonParticipantWhen you deploy your application using MyEclipse, are the class files deployed in WEB-INF/classes? Is there any difference you can see between the deployment you did manually and either the packaged or exploded one you did with the IDE? There must be something if one is working and the other is not.
wsheafferMemberYes there is. In the MyEclipse hierarchy you separate source into the src directory and classes go into the WEB-INF/classes directory. In my deployment and in development I have them in the same directory. The problem it seems is this separation of Java code into one directory and the classes into another. This is why I feel I may have some type of system classpath problem, or perhaps the path is not being interpreted correctly from within the IDE.
Thank you for your prompt reply.
Scott AndersonParticipantIn the MyEclipse hierarchy you separate source into the src directory and classes go into the WEB-INF/classes directory. In my deployment and in development I have them in the same directory.
That may be true, but Java source does not need to be deployed. As long all the classes are in WEB-INF/classes, your JSPs are under your web root directory in the deployed version, *and* you’ve added the import statements I mentioned in my earlier post then the project should work fine. Are all three of these the case?
wsheafferMemberi have done all that you said, refreshed the project to no avail. I still believe this is some sort of build path issue and there is a relatively simple solution to it.
Scott AndersonParticipantFor closure, the project was sent in and the error was that the JSP page did not include an import statment for the Java class being referenced. As I instructed in my second followup post, once the import was added, validation worked as expected.
wsheafferMemberHello my name is Tim Willson, ITS 5 with the Minneosota Department of Finance.
Warren Shaffer is conducting a training class and we have hit this bean problem.
On Warren’s machine the project runs correctly but with the student machine we see a 500 error. I’ve zipped the project into a file that I can send you. “org.apache.jasper.JasperException: /SaveName.jsp(28,2) The value for the useBean class attribute UserData is invalid.”
Basically the
<%@ page import="us.mn.state.finance.*" %> <jsp:useBean id="user" class="us.mn.state.finance.UserData" scope="session"/>
works correctly in the .jsp file but the
<%@ page import="us.mn.state.finance.*" %> <jsp:useBean id="user" class="UserData" scope="session"/>
Our setter.jsp file has the following code
<%@ page import="us.mn.state.finance.*" %> <jsp:useBean id="user" class="us.mn.state.finance.UserData" scope="session"/> <jsp:setProperty name="user" property="*"/>
works correctly in the .jsp file and
<%@ page import="us.mn.state.finance.*" %> <jsp:useBean id="user" class="UserData" scope="session"/> <jsp:setProperty name="user" property="*"/>
did not.
It appears to be a default search path of sorts or a configuration setting in not finding the class.
-tw
Scott AndersonParticipantTim,
The issue is that, per the JSP spec, import statements are not taken into account when processing tag attributes. They only affect Java scriptlet code. So each time you use your class as a tag attribute, you *must* fully specify it like:
<jsp:useBean id="user" class="us.mn.state.finance.UserData" scope="session"/>
not like this, since the spec does not support it.
<jsp:useBean id="user" class="UserData" scope="session"/>
emz005MemberFor closure, the project was sent in and the error was that the JSP page did not include an import statment for the Java class being referenced. As I instructed in my second followup post, once the import was added, validation worked as expected.
What should the import statement look like exactly.
Scott AndersonParticipantAn import of a Java class in a JSP page is done with the ‘page’ directive as shown below:
<%@ page import="java.util.Date" %>
When you’re typing in a a classname in a Java scriptlet in a JSP page, typing ctrl+<space> after the name will add the import for you automatically.
-
AuthorPosts