• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Add my own class to JSP - ResultSet cannot be resolved to a type

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to use a custom class in a .jsp page, as part of a course I am taking on Web Technologies.

The original version of the jsp page was working fine, until I moved part of the Java code to a separate class.

Here is the original .jsp code that is working:



Here is the Java class I created:



And here is the .jsp page after I replaced part of the code with the Java class:



Here is the error message I get:



Finally, I attach a screenshot of my file manager, to show that I did save the class under the appropriate folder: ROOT/WEB-INF/classes/com/stocktails/DbConnect.class
Filename: screenshot.tiff
File size: 131 Kbytes
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not a good practice to have Java code in JSP. Create a servlet and do all processing there and then return results to be used in JSP.

In your case right now, you have ResultSet class used in your JSP, but you removed the import statement, hence the error.
 
Sheriff
Posts: 28370
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your course really teaching you to put scriplets into a JSP??? That's been an obsolete technology for a decade now.

I suppose it's true that it might be helpful to know how that works, in the likely case that you get stuck cleaning up some old application. But the course really ought to be telling you seriously not to use scriptlets in new code. Hopefully that's the case.

Anyway... you have to import the ResultSet class into the JSP, just like you have to import it into Java code which uses it. You haven't done that. Sorry, I can't tell you how to do it because I haven't written JSP code with scriptlets for years now but it should be covered in your course material somewhere.
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surendra, I thank you for your reply. I cannot use servlets for this coursework, as it was discouraged by our professor who expressly requested that we use Java in .jsp pages instead. I do think your point is valid, as I have repeatedly seen the same remark elsewhere.

Coming back to my problem, I get a different error when I add <%@ page import="java.sql.ResultSet" %> to my .jsp page, as suggested by you:


After I posted my initial message, I created another much more simple .jsp page, to try to isolate the problem. It does seem that the problem lies with the class DbConnect.



This results in the following error:
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You created DbConnect class but what package is it in? Use the same one in your JSP too.
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surendra,

I saved the class under ROOT/WEB-INF/classes/com/stocktails/DbConnect.java and I then compiled it from ROOT/WEB-INF/

LC
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, I attach some extracts from my course's slides where it says not to use servlets. Personally, I am new to JSP and I therefore do not have a view of my own. But I see the consensus seems to be that servlets are the better solution.

LC
Filename: servlets2.tiff
File size: 182 Kbytes
Filename: servlet.tiff
File size: 142 Kbytes
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the real world, it's never a question using one of servlets or JSP; servlets and JSP are always used together. Each is a tool used for its own strengths, just like a carpenter will use both a saw and a drill to get a job done.

In an academic environment things are different to focus effort on a single concept.
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear, I thank you for your comment. It helps me put these slides in a new light. Once I am done with my studies, I will need to pursue my education Web Technologies. I will then have a look into this in more detail. This trimester, I have to learn Java, Web Technologies (HTML, CSS, Javascript, Tomcat, JSP) and SQL all at the same time. No need to say, I lack perspective on what I am learning...

LC
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your DbConnect class code you posted, I don't see package statement.
Is it not copied here while posting or you don't have it in the class?
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surendra,

The tutorial I use says I have two options:

1) not to create a package but save the class under ROOT/WEB-INF/classes/com/stocktails/DbConnect.java and compile it from ROOT/WEB-INF/
$ javac com/stocktails/DbConnect.java

=> this is what I did until now

2) to create a package:

$ javac com/stocktails/DbConnect.java
$ jar -cf stocktails.jar com/stocktails/*.class

I then moved the package under ROOT/WEB-INF/lib

Finally, I added the following line to DbConnect.java:
package com.stocktails;

I just tried the second solution, but unfortunately, I still get the same error message.

LC
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally took a look at those slides. Egads! Be sure to take them with a grain of salt -- I disagree with almost everything they say.

In fact, the statement about always using JSP is so wrong as to be almost criminally negligent.

Please be advised.
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
P.S. If you want to "read ahead" check out this article which gives you an overview of how web apps in the real world are constructed.
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear, thank you for sharing this article. It is very instructive. I see there is so much to learn...

LC
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surendra,

It now works! I tried again using the second solution and the JSP page now functions.

I thank you very much for your guidance and your patience.

Best regards,

LC
 
Paul Clapham
Sheriff
Posts: 28370
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lienol Crazel wrote:I see there is so much to learn...



Yeah, Java + HTML + CSS + JavaScript + SQL + JSP does look like quite a dog's breakfast, doesn't it? But nevertheless that's what we're stuck with when creating Web applications.
 
Lienol Crazel
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should I also consider learning a Web Development framework (such as Play, since we are talking Java)? I am still unsure how these frameworks relate to what I am learning now.

LC
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Learn the basic first, before diving off into any frameworks.
 
You firghten me terribly. I would like to go home now. Here, take this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic