• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cannot import file

 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Java class that is used by a JSP page.
I have placed the class file under tomcat/webapps/MyJsp/WEB-INF/classes directory.
The JSP code is


The java code is a follows:


What is wrong in the code?
What do i have to write in the page directive when i have placed the file just under the classes directory?

The error that i get after compiling the JSP is as follows


The JSP cannot find the CounterClass but i have put it under the correct directory structure.....

I am very new to JSP.


Please help.

[ November 12, 2008: Message edited by: Sudipto Shekhar ]
[ November 12, 2008: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your classes need to be packaged in order to import them from a JSP
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This FAQ entry explains why and includes a link to the original Sun bug report that explains it further.

http://faq.javaranch.com/java/PackageYourBeans
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for the hint.
The question may seem silly but why do we have to package the classes?
Is it mandatory to do so?
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much for the link and the help.
As i am just a beginner to JSP and want to complete JSP fast, help for me is great.
Thank you once again.
[ November 12, 2008: Message edited by: Sudipto Shekhar ]
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have one more doubt and seek advice for that.
I am using NetBeans IDE 4.0 for the purpose of learning JSP.
I have completed the servlet part using Tomcat 5.0.
Is it necessary for me to use Tomcat for learning JSP too?
[ November 12, 2008: Message edited by: Sudipto Shekhar ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP is built on top of Servlets so, yes, you will need a servlet container such as Tomcat.
[ November 12, 2008: Message edited by: Ben Souther ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sudipto Shekhar:
I have a Java class that is used by a JSP page.
I have placed the class file under tomcat/webapps/MyJsp/WEB-INF/classes directory.
The JSP code is


The java code is a follows:


What is wrong in the code?
What do i have to write in the page directive when i have placed the file just under the classes directory?

The error that i get after compiling the JSP is as follows


The JSP cannot find the CounterClass but i have put it under the correct directory structure.....

I am very new to JSP.


Please help.

[ November 12, 2008: Message edited by: Sudipto Shekhar ]

[ November 12, 2008: Message edited by: Bear Bibeault ]





Try it by changing the import statement.

Import the class explicitly by specifyiing the class name.

It may work for you.
 
Sheriff
Posts: 67746
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
"VenkataNarayanaReddy Pingala", please check your private messages for an important administrative matter.
 
Bear Bibeault
Sheriff
Posts: 67746
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
Also, "VenkataNarayanaReddy Pingala", while we appreciate your enthusiasm in wanting to help, there is no need to try and answer questions that have already been correctly addressed -- especially when the answer is, well, not so correct.

Classes that are not in packages cannot be imported into a JSP, explicitly or otherwise.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic