Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web application in Eclipse : object cannot be resolved to a type in JSP

 
nimesh subramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting the following error.....
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 17 in the jsp file: /output.jsp
ServicePolicy cannot be resolved to a type
14: //ServicePolicy
15: String s = (String) session.getAttribute("heehe");
16: out.println("Hello "+s);
17: ServicePolicy obj = (ServicePolicy) session.getAttribute("policy");
18: //out.println("hello1" + obj.Availability);
19: //ServicePolicy p = new ServicePolicy();
20: Object p = (Object) session.getAttribute("policy");


Here servicepolicy is a java class that is there is src folder....
i have one more servlet which calls this output.jsp file.....in that a ServicePolicy object is putinto the session...
when i build it ...there are no errors...but when i run it ...this error comes...
what do i do??
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were not using scriptlets, you wouldn't have such trouble !
Anyway, you need to import your class via the page directive. If your class is not in a package, put it in one.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed. Scriptlets and Java in JSPs have been discredited for over 8 years now. Time to update your JSP knowledge.
 
nimesh subramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
initially i thought that might be the problem and added a page directive to it...still the problem persists..

i even did ctrl+left click on the class in "eclipse" and it led me to the java page were i had defined the class...

in the JSP page..i created an object of my class...and then i realized that i couldn't access any of the variables that have been declared in it...

@Bear could you please explain what you ment by scriptlets and java in JSP has been discredited.......
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i even did ctrl+left click on the class in eclipse and it led me to the java page were i had defined the class...

The fact that Eclipse knows where to find the class doesn't necessarily mean that Tomcat will know where to find it. Please show your page directive.

Also, your class file should be under the WEB-INF/classes directory of your application. Is it ?
 
nimesh subramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my import statement




i'm running my code from eclipse... and i cant find any .class file...in the project explorer window under my project....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The package explorer is used to show packages, classes and resources, not .class files. You can see them in the Navigator view.

Are you using a plugin to launch Tomcat ?
 
nimesh subramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the classes are in build/classes/...folder

when i click them and open them...it says.. "source not found. There is no source file attached to the class file filename.class"

yes. Added the tomcat that i installed into the serverruntime envirnoment and running it from eclipse....
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not a JSP problem that you have here, but an Eclipse problem. Make sure your web application is configured to use your class files. I'm moving your thread to the Eclipse forum.
 
Fintan Conway
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:This is not a JSP problem that you have here, but an Eclipse problem. Make sure your web application is configured to use your class files. I'm moving your thread to the Eclipse forum.


Hi,

How do I do the above?

Many thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic