• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic