This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Question related to Tomcat /JSP  RSS feed

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JSP file, called testConnection.jsp which uses a ConnectionBean.java to connect to JDBC database. Work is being done in UNIX platform.
The ConnectionBean.java is working fine when tested with a main method - it accesses and retrieves the data. Also, I am able to view a ordinary JSP page on the browser. I have made appropriate changes to the server.xml file in tomcat installation.
I get an error saying that the package ta does not exist. Even if I remove the package name from the files, the error persists, now the error being class ConnectionBean symbol cannot be resolved.
Is the error is related to setting the CLASSPATH (UNIX platform)? I have copied my friend's CLASSPATH from his .cshrc (which he'd used successfully for his own code, to access the same database). That didn't solve the problem.
I'd appreciate any feedback at the earliest.
Thanks,
Saket
 
Author
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI there.
In order to make this work, you will need to package your JSP and classfiles up into a web application. A Simple structure chould look like:
(this is within the Tomcat/webapps directory)
/mywebapp
myjsp.jsp <- all JSPs go at this level
/WEB-INF <- case sensitive
web.xml <- if appropriate
/classes
/mypackage <- ta in your case
/myclass.class

More information can easily be found here
Hope this helps
Sam
 
Saket Barve
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Sam.
My directory structure is indeed just as you have described in your message. The problem persists.
I seem to be missing out on something trivial, yet not quite!
If anyone has ideas/suggestions, please do let me know.
Thanks,
Saket
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you import the bean class in the JSP page?

There is a special JSP tag that will import external classes, much like in a regular java class you need to "import java.net.*;"
 
Saket Barve
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion Mike.
I realized that after making changes to the .java file, I wasn't compiling them to get the latest (and appropriate) .class files for the .jsp page to work on.
Being new to JSP, I wasn't not aware of the need to compile the XXXXBean.java file everytime I make a relevant change.
Saket
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something that frequently trips people up: in your jsp:useBean tag you MUST give the complete package with the class name in addition to importing the class with an import statement as Mike says.
Bill
 
When people don’t understand what you are doing they call you crazy. But this tiny ad just doesn't care:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!