Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6660649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:10:53+00:00 2026-05-26T02:10:53+00:00

I have the following JSP: <%@ page import=foo.* %> <html> <body> The page count

  • 0

I have the following JSP:

<%@ page import="foo.*" %>
<html>
    <body>
        The page count is:
        <%=Counter.getCount()%>
    </body>
    </html>

I have a Counter class in package foo which is stored in:

C:\apache-tomcat-6.0.32\webapps\God\WEB-INF\classes

And the container could find the class from its package foo.

But when I try to add some other class file directly under \WEB-INF\classes and not in any specific package such as foo, then container can’t find that class.

How is this caused and how can I solve it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:10:53+00:00Added an answer on May 26, 2026 at 2:10 am

    Classes in the default package are not visible to classes which are by itself inside a package. You must put the class in a package whenever you want to import it in another class which is by itself inside a package. Technically, when JSP files are compiled, the container will autogenerate a .class file which is by itself inside a package. So you cannot import classes from the default package in the JSP.

    So, whenever you want to be able to reuse a class anywhere, it has to be placed in a concrete package, not in the default package. As an exercise, create two classes yourself, one which is inside a package and other which is not inside a package. Now, inside the one with package, try to import and use the one without package. You’ll see that it’s not possible and the code won’t compile. The servletcontainer encounters exactly the same problem "under the hoods".

    See also:

    • The Java Tutorial – Lesson: Packages

    Unrelated to the concrete problem: writing raw Java code in JSP files is a poor practice. Consider learning and using servlets.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following files: view.jsp <@ page import=... <bean:define id=mForm name=myForm type=MyForm/> <html:form
I have an instance of the following object in the jsp page context: Class
I have the following code in a jsp page (Struts backed): <c:if test=${USERINFO.someproperty ==
I have an application web.xml with the following entry: <error-page> <error-code>404</error-code> <location>/system_files/error/p_notfound.jsp</location> </error-page> However,
I have the following function call inside a jsp page. jQuery(function($){ $(#product).mask(99/99/9999,{placeholder: }); });
i have the following code from my JSP which doesn't quite work: <%@ taglib
I would like to have a single JSP page that will do the following:
I have the following in my jsp page (assume that client is an object
I have a JSP page running on Tomcat 5.5. I have the following code:
I have the following block of code that works just fine: <%@page import="java.util.*" %>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.