I have a standard java web application package under public_html. My java source code is under WEB-INF/classes/. My jsp files are under public_html and public_html/version/v1. Now all of my jsp file under public_html is running fine, however, the jsp files under public_html/version/v1 do not work with following error:

*HTTP Status 500: Unable to compile for class JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 8 in the jsp file: /index.jsp
Utility cannot be resolved to a type *

Utility is one of my java file under WEB-INF/classes.

It looks like there is a problem with tomcat configuration of either server.xml or web.xml. Can anybody help me to make the jsp files under public_html/version/v1/index.jsp work?

Thanks,

Dani AI

Generated

Short diagnosis and likely cause (for ): the JSP compiler cannot see your Utility type. The most frequent cause for this exact error is a package/visibility mismatch — for example Utility lives in the unnamed (default) package or its package declaration does not match the folder layout. Java forbids classes in the unnamed package from being referenced by classes in a named package, and Jasper (Tomcat’s JSP compiler) generates servlets in a named package (default org.apache.jsp), so a JSP-generated servlet cannot access a default-package class. (docs.oracle.com)

Where the class must live and how Tomcat finds it: Tomcat’s webapp class loader loads classes from WEB-INF/classes and JARs from WEB-INF/lib. Put compiled classes in WEB-INF/classes using a directory layout that matches the package statement, or package them into a JAR in WEB-INF/lib. Also clear Tomcat’s work/generated JSP output after changes so JSPs are recompiled. (tomcat.apache.org)

Concrete fixes (in order):

  1. Move Utility.java into a named package and compile it. Example source top lines:
    
    package com.example.util;

public class Utility { ... }

2) Place the class file at `WEB-INF/classes/com/example/util/Utility.class` (or jar it in `WEB-INF/lib`).  
3) In the JSP add an import for the fully qualified name or use the FQCN inline:

<%@ page import="com.example.util.Utility" %>


4) Remove any servlet-api/jsp-api jars from `WEB-INF/lib` (these conflict with Tomcat’s own libs), clear Tomcat’s `work` folder and restart so Jasper recompiles JSPs. ([stackoverflow.com](https://stackoverflow.com/questions/17518049/org-apache-jasper-jasperexception-unable-to-compile-class-for-jsp?utm_source=openai))

Quick troubleshooting checklist: confirm the `package` line matches directory layout, verify the `.class` exists under `WEB-INF/classes` (respect case sensitivity), check Tomcat logs (`catalina.out` / logs) for compiler errors, and include Tomcat/Java versions and a minimal project layout when asking for more help (as @esprittn suggested).

It is possible to get a copy of your project to test it and could you tell me what version of java and tomcat you use?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.