1

I am trying to build a dynamic web app using Eclipse Helios. I am trying to use a java class inside a jsp page. The page is visible during coding and deployment. In the runtime the java classes are not resolved to a type. Why does this happen?

Update: Directory structure as in eclipse

 Restarunt JAX-WS Web Services
 Deploymment Descriptor Java
 Resources:src
     default package
       LoginBean build WebContent    WebINF
      lib
      web.xml
      weblogic.xml jsp files
Cœur
  • 37,241
  • 25
  • 195
  • 267
Harish
  • 3,343
  • 15
  • 54
  • 75

3 Answers3

3

Classes in the default package are invisible/unimportable by classes in a package. JSP files end up as a class in a package, so it will be invisible to JSP as well. This works in very specific (Tomcat) environments only, you don't want to be dependent on that. Just put classes in a package. Always.


Unrelated to the problem, writing Java code in a JSP is a poor practice. Use a Servlet.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
2

Have you added in jsp, and this classes are in class path or is in the WEB-INF/classes after build

<%@ page import="java.util.*,yourpackage.yourClass" %>
jmj
  • 237,923
  • 42
  • 401
  • 438
  • its in default package.I checked in properties the output folder is build/classes and it will be moved to WEB-INF while deploying. – Harish Dec 14 '10 at 19:26
  • @Harish it should be in `/WEB-INF/classes/` also can you please make sure that you have made proper imports in jsp from answer given – jmj Dec 14 '10 at 19:29
  • just now tried.It doesn't work.I have no problem while coding or deploying but why while running alone? – Harish Dec 14 '10 at 19:31
  • @Harich, can you please update your Q. with your dir structure ,along with exception you are getting – jmj Dec 14 '10 at 19:33
  • 1
    @Harish you need to provide enough stactrace as well as dir structure in Question – jmj Dec 14 '10 at 19:43
2

If FQN of your class is your.package.YourClass then make sure your class deploys to:

YOUR_WEB_APP.war \
    WEB-INF \
        classes \
            your \
               package \
                  YourClass.class
Pablo Santa Cruz
  • 176,835
  • 32
  • 241
  • 292