0

I'm trying to get my first jsp page running and it does not work as I expect it to. I'm using Tomcat7 + Eclipse.

First I created my framework.java file and put it in: \ROOT\WEB-INF\classes\framework.

Then I successful compiled it so I got: \ROOT\WEB-INF\classes\framework\Layer1.class, Layer2.class, Layer3.class Then i did the actual jsp file:

<%@ page import="framework.Layer1" %> <%= Layer1.write() %> 

Now, even Eclipse at this point gives me the warning: The type framework.Layer1 is not visible. And when I run the page, naturally it says: The type framework.Layer1 is not visible.

What am I doing wrong here? I tried all tutorials I found and all had the same issue. Any suggestions?

1 Answer 1

4

You are in the right path, but you need to make sure Layer1 is a public class.

So, your Layer1 class must be something like:

package framework; public class Layer1 { public String write() { return "hello"; } } 

Instead of:

package framework; class Layer1 { // do note the non-use of public keyword here } 
Sign up to request clarification or add additional context in comments.

5 Comments

Yes, i tried that but then javac says: framework.java:4: error: class Layer1 is public, should be declared in a file named Layer1.java
Yes, you need to use one-file-per-class approach java uses. Unfortunately, this is not C#. :-)
But, then what is the package for? Do I need to have 3 files all package framework and each with one class?
@JamieFlowers: yes. In java, yes. framework will be a directory with three files: Layer1, Layer2 and Layer3.
Unfortunately I still get the same error, but i discovered that when I do <%@ page import="framework.*" %> Eclipse will not show an error.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.