2

I'm quite new to tomcat and JSP in general, I also have searched countless other questions that appear to have the exactly same problem but none solved my problem.

the server structure contains (amongst other things like a css file and other html ressources) a jsp file and a java class:

.../webapps/[appname]/test.jsp
.../webapps/[appname]/WEB-INF/classes/beans/Bean.class

the jsp file contains:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%>
<%@ page import = "beans.Bean" %>
<html>
    <head>
        <link href="css.css" rel="stylesheet" type="text/css">
        <title>title</title>
        <meta charset="utf-8">
    </head>
    <body>
        <%= new String((new beans.Bean()).foo())%>
    </body>
</html>

And the source file for the Java class looks like so:

package beans;

public class Bean {

    public String foo() {
        return "Success";
    }
}

Now I (re)start the tomcat server and access the jsp file with my browser and get the follwong error message:

Unable to compile class for JSP: An error occurred at line: 14 in the generated java file Only a type can be imported. beans.Bean resolves to a package

As well as:

An error occurred at line: 10 in the jsp file: /tilt.jsp beans.Bean cannot be resolved to a type

By changing the import like so:

<%@ page import = "beans.*" %>

And then restarting tomcat before trying again, I can remove the first error, but the type of my class is still not recognized. What do I need to do in order to make this simple project work?

I believe I'm using tomcat7.something and the class files were compiled with java jre 7.

Zarylo
  • 23
  • 5
  • More details: Tomcat version is 7.0.28 Java: JDK1.7_01 – Zarylo Mar 17 '16 at 08:07
  • well, your app looks OK, can you shutdown tomcat, go to `/work/Catalina/localhost/` and delete the directory having your `[appname]`, then start tomcat and try to open that page, (this is like a cleaning process) for files related to your app – Yazan Mar 17 '16 at 08:25
  • I've followed your instructions, however tomcat does not behave differently. It's an odd problem. It did all work yesterday. – Zarylo Mar 17 '16 at 09:15
  • Arrrgh, well no wonder it did not work. I think I found my issue. Se my own answer below. This is embarassing. – Zarylo Mar 17 '16 at 10:14

1 Answers1

0

Okay, this is almost embarassingly stupid. The Setup I have posted in my question works perfectly fine like it is. I accidentally skipped to create the class folder where beans/Bean is supposed to be. (In other words I asked people to find an error where none was to begin with. I just made a trivial misstake.)

In essential I had the following setup:

.../webapps/[appname]/WEB-INF/beans/Bean.class

instead of this:

.../webapps/[appname]/WEB-INF/classes/beans/Bean.class

Thank you to Yazan, Elyas and everyone else who tried to help me out!

Zarylo
  • 23
  • 5