Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Can't open a DataSource.

Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this is the right place for my question, if this is not, please redirect me to the right one.

From some place in the web i copied the stuff to connect to Mysql using a DataSource and tried to adapt to my application.
It doesn't work.
I am using Tomcat 9.0.10, Mysql 5.7.

The problem is i am receiving 2 errors and i think they are the result of a bad connection.

Here are the errors:

25-Aug-2018 06:30:22.756 SEVERE [http-nio-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jsp] in context with path [/agenda] threw exception [Unable to compile class for JSP:

An error occurred at line: [17] in the jsp file: [/validate.jsp]
rsAgenda cannot be resolved
14:      <sql:param value = "${password}" />
15: </sql:query>  
17: <% if (rsAgenda.size() != 1) { %>
18:   <ora:redirect page="login.jsp" >
19:    <ora:param name="errorMsg" value="Clave de Usuario y/ Password son invalidos" />
20:   </ora:redirect>

An error occurred at line: [25] in the jsp file: [/validate.jsp]
rsAgenda cannot be resolved
22: <%--
23: Crea una userJavaBean y la guarda en session scope.
24: --%>
25: <% Row oneRow = (Row) rsAgenda.firstElement(); %>
26: <jsp:useBean id="validUser" scope="session" class="com.ora.jsp.userJavaBean" >
27: <jsp:setProperty name="validUser" property="usuario" value='<%= oneRow.getString("usuario") %>' />
28: <jsp:setProperty name="validUser" property="password" value='<%= oneRow.getString("password") %>' />

Stacktrace:] with root cause
org.apache.jasper.JasperException: Unable to compile class for JSP:

And here is the validate.jsp  program:

The context.xml:[/u]

<Resource name="jdbc/Mysql1" auth="Container" type="javax.sql.DataSource"
              maxTotal="100" maxIdle="30" maxWaitMillis="10000"
              username="root" password="root" driverClassName="com.mysql.jdbc.Driver"

[b]The web.xml:[/b]

<web-app xmlns="";
 <description>MySQL Agenda App</description>
     <description>DB Connection</description>

Any ideas?
Any help is welcome.


Posts: 21943
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is probably caused because you mix (JSTL) tags and scriplets. Try replacing the latter with proper JSTL tags: c:choose with c:when and c:otherwise instead of the if / else, and c:set instead of the directly declared variable.

It's been a while since I did any JSP programming, but I think the problem is scope. Inside scriplets, you are using variables that exist directly in the JSP's service method (which is generated for you). In JSTL tags the variables are bound to a specific scope (session, request, etc). You can probably access rsAgenda in your scriplets using request attributes, but it's safer to just not use scriplets at all.
Saloon Keeper
Posts: 22104
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I hear a Bear growling in the distance?

Logic should not be coded on JSPs. It's an antiquated style with many disadvantages, but perhaps the worst of them is that it's virtually impossible to run a JSP through a debugger.

In fact, I really don't even recommend using the SQL JSTL tags. Do all the work in a Controller Servlet (which can be easily run through a debugger) and present the results as a simple sequential collection (array, List, or something similar).

Beyond that, you're coding your own login system instead of using the one that comes standard as part of JEE. The technical term for "Do-it-Yourself security" is "hacked".
rafael muneton
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Rob and Tim.
I will follow your recommendations, will replace scriplets with JSTL tags and later i will go for a controller servlet.

Anyway i will keep you posted.

Thank you guys.

Ruth Stout was famous for gardening naked. Just like this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic