Tomcat 7 compile error for simple JSP/Class

ben fran

Greenhorn

Posts: 7

posted 4 years ago

Hi,

I am a newbie to Java technologies, and so my question might sound very simple. I searched a little and got some tips to solve my problem in some forums, but they didn’t work. So I am seeking coderanch people help.
Please have a look at it, and see if I am missing any obvious steps(I don’t think I am, but the task is so basic I have my doubts).

• Objective: o To run a JSP page which calls a java class, both residing on tomcat server
o Then proceed to run a JSP page which calls a java class, which in turn calls a jdbc driver class, residing on tomcat server

Don't use all uppercase for HTML markup. It's a sure sign of a n00b. Use all lowercase.

Java scriptlets in JSPs have been obnsolete and discredited for over 10 years now (the constructs delimited by <%). You should be using modern techniques such as the JSTL and EL.

If you back up a bit and apply the 2nd of the suggestions listed above, your question becomes entirely moot as you would not be trying to directly access a Java class from the JSP in the first place.

Is this new code, or are you trying to fix legacy code? If the former, you are certainly heading down the wrong path. (Analogy: trying to use vacuum tubes to build an HDTV.) If the latter, then you obviously need to work with what you've got.

Regardless, I always recommend that newcomers to Java web apps read the following articles:

If you continue on your current path (not recommended, as discussed above) then the problem is that your class isn't being imported. Is the class file in the right place?

Another issue: "HelloWorld" while syntactically valid is not an acceptable package name by Java conventions. Package names should be all lowercase (and simply repeating the name of the class isn't very descriptive).

I appreciate your reply. I have seen while looking at some java issues, this forum is very helpful.

The java class is designed or rather written in this way:
*Package: HelloWorld(I see what you meant about naming)
*ClassName: HelloWorld(what else?)
*Class Location: TOMCAT/webapps/hello/WEB-INF/classes/HelloWorld/HelloWorld.class

So it appears to be in the correct location. Unless I am wrong in assuming WEB-INF/classes/(PACKAGE)/(CLASS) is the location where the TOMCAT servlet engine looks for classes which are imported by the JSP page.
Thats one reason I said it might be a config error, but I really dont know what is there to configure here?

I have to use JSP, for not this project :), but the reason why I am trying to get this working :)

My broad objective is to run a JSP form which refers to some data access classes, which in turn refer to a jdbc driver jar.
Before getting my hands on them , I just want to make sure I can run a JSP on TOMCAT which refers to an external class.
That is why I am trying this.

Again, barking up the wrong tree. JSPs should not be accessing Java classes. But if you insist on getting this working (though it will be not very useful going forward), is the method static? I've been assuming so, but...

Looking at the deployment descriptor, I assume that the leading "o" characters are an artifact of posting?

Why do you have a servlet declaration for the JSP? Not needed. And superfluous things tend to have a way of sticking their legs out and tripping you when you least expect it. I'd clean that up before progressing.

Looking at the deployment descriptor, I assume that the leading "o" characters are an artifact of posting? : they are lists from MS Word

Why do you have a servlet declaration for the JSP? Not needed. so just a web.xml will do with no elements? that was one thing I suspected may cause my issue. But it appears it wasnt.

And superfluous things tend to have a way of sticking their legs out and tripping you when you least expect it. I'd clean that up before progressing. agree, let me clean web.xml and try to run it.
UPDATE: same error

ben fran wrote: for getting
*A simple JSP form
*A JDBC using bean
to work together on apache tomcat 7?

Firstly, stop thinking just Tomcat. What you write should conform to the Servlet/JSP specs and not be tied to a particular server.

Next, the 100-mile overview:

Never directly address a JSP, hit a servlet that serves as the page controller.

The controller does all the "prep work" (think of it as the sous chef for the JSP) and forwards to the JSP.

DB access occurs in the model layer, not the controller or view. So never in a servlet.

The servlet uses a model class to get stuff from the DB. It places it in request scope prior to forwarding to the JSP. That's where the JSP gets it from. This sort of data is known as a scoped variable.

At no time should the JSP ever have scriptlet code in it. JSTL and EL are the modern mechanisms to access the scoped variables that the controller provides.