This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Can't open a DataSource.  RSS feed

 
Greenhorn
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>  
16:
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"
              url="jdbc:mysql://localhost:3306/javatest?serverTimezone=UTC&useLegacyDatetimeCode=false&time_zone='+00:00'"/>

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

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">
 <description>MySQL Agenda App</description>
 <resource-ref>
     <description>DB Connection</description>
     <res-ref-name>jdbc/Mysql1</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
 </resource-ref>
</web-app>

Any ideas?
Any help is welcome.

Sincerely,
Rafael


 
Sheriff
Posts: 21719
102
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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: 20643
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • 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
Greenhorn
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.

Rafael
 
Skool. Stay in. Smartness. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!