• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

context xml, web xml, jdbc, mysql - which way did they go?

 
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All, thanks for taking a look at my question.

I have a working jsp/servlet app running on apache and tomcat 7. but I am not sure about the program flow.
I have the following setup (actual questions at bottom of post).

context.xml -

web.xml - listener setup, but no resource-ref


connServletListener.java


DbConnectionClass.java



testjdbc.jsp


I apologize for the long preliminary. As I understand it this is how the app should work

at startup context.xml and web.xml are read, then the listener is called which in turn calls the dbconnectionclass that creates a datasource object and some testjdbc.jsp uses this datasource.

This app actually works, and the servletListener examples I have seen say that a resource should be in web.xml. Why does this app work with out it?
What is it that is calling the Connection getConnection() method of DbConnectionClass?
In jdbcTest.jsp is <sql:query..... dataSource="jdbc/printShop"> somehow going around or ignoring the datasource object created by DbConnectionClass?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is ignoring that object. The two Java classes and the listener declaration in web.xml do precisely nothing.

Let's turn around and ask: How (or why) do you imagine they could be doing anything?
 
bob von ilten
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well basically because I don't know what I am doing. :-) The reading I have done to this point suggests to me that context.xml, web.xml, listener, connection, and view pages are all necessary to make a functioning web app with a database object. I knew that I had something wrong but I am still not sure what. At this point I am guessing that the web.xml is wrong and that my jdbctest page needs to be written somehow use the datasource object if indeed one is even being created.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, Tomcat manages all that for you. That's what the "Resource" declaration in the context is for. It defines the "jdbc/printShop" datasource that the JSP then references. That's really all there is to it :-)
 
bob von ilten
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so what exactly is extraneous then? web.xml seems to be, but if I comment out the call to DbConnectionClass from the listener the testjdbc.jsp will fail on the query line. There must be something linking the datasource in testjdbc to the DbConnectionClass?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's odd. I just tried it locally to make sure it worked, and sure enough once the Resource is declared in the context, it can be used in a JSP. What error message are you getting?
 
bob von ilten
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got a resource not found error. So when you tried it yourself you only used the context.xml, and the jdbctest.jsp files?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
 
bob von ilten
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, I will start a new project from scratch and see if I still get the error.
 
reply
    Bookmark Topic Watch Topic
  • New Topic