0

I'm trying to use JSTL to hook into an Oracle database. I have it working, but not in the way I'd like. (The values for USER and PASSWORD have different values in the actual program but I didn't want to share them publicly)/

<c:set var="DRIVER" value="oracle.jdbc.OracleDriver" scope="request" />
<c:set var="URL" value="dbc:oracle:thin:@localhost:1521:xe" scope="request" />
<c:set var="USER" value="REDACTED" scope="request" />
<c:set var="PASSWORD" value="REDACTED" scope="request" />


<sql:setDataSource var="dbDataSource" driver="${DRIVER}" url="${URL}"
    user="${USER}"  password="${PASSWORD }" />

So it's working, but I don't like using those string literals. I have some static final int variable set in another Java class that hold the values so I can change them in one place if I need. I can't figure out how to access these constants in my JSP file.

I tried using a bean, then setting a JSTL variable:

<%@ page import="myPackage.dbInfo" %>
<jsp:useBean id="dbInfoBean" scope="request" class="myPackage.dbInfo"></jsp:useBean>

And my class "dbInfo" contains the following definition for the DRIVER variable.

public static final String ALSODRIVER = "oracle.jdbc.OracleDriver";

Finally replacing the first of those fields as such:

<c:set var="DRIVER" value="${dbInfoBean.DRIVER}" scope="request" />

When I try to run the JSP, it doesn't work. I get errors:

org.apache.jasper.JasperException: An exception occurred processing JSP page /authorize_registrations.jsp at line 13

12: 
13: <c:set var="DRIVER" value="${dbInfoBean.ALSODRIVER}" scope="request" />
14: <c:set var="URL" value="dbc:oracle:thin:@localhost:1521:xe" scope="request" />
15: <c:set var="USER" value="REDACTED" scope="request" />
16: <c:set var="PASSWORD" value="REDACTED" scope="request" />

What am I doing wrong? I'll use the string literals (which are working) if I have to, but I'm not crazy about it if I can avoid.

mstabosz
  • 55
  • 2
  • 9
  • Yes thanks. I forgot to come back to it until now. I'm not familiar with the UI on this board.... is there a button I should click to "accept" it? – mstabosz Aug 25 '15 at 13:42

2 Answers2

0

it should be

   <c:set var="DRIVER" value="${dbInfoBean.ALSODRIVER }" scope="request" />

                       instead of 

    <c:set var="DRIVER" value="${dbInfoBean.DRIVER }" scope="request" />

as your static field name is ALSODRIVER not DRIVER

M Sach
  • 33,416
  • 76
  • 221
  • 314
0

for accessing the static field no need for usebean

<c:set var="DRIVER" value="${dbInfo.ALSODRIVER }" scope="request" />
Vincent
  • 141
  • 5