Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot import file  RSS feed

 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 ]
 
Venkat Pingala
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"VenkataNarayanaReddy Pingala", please check your private messages for an important administrative matter.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!