Stanley Mungai
Stanley Mungai

Reputation: 4150

Get ServletContext Connection to JSP

I am Connecting to the database at initialization of my Application through ServletContext Listener. I am able to utilize all the Connection I get from the database except the Connections where I am passing values direct to the JSP without Going through the servlet.

For Example I have a Vector Method in My DAO Class that returns a Collection of values which I am populating to a drop down in the JSP like this:

<jsp:useBean id="obj" class ="mypackage.MyDAOClass" scope="page"/>

......

My drop down

<c:forEach var ='item" items=${obj.campusCodes}">
<option>${item}</option>
</c:forEach>

I have set an attribute database in My ContextServletListener like this:

Connection conn = db.getDBConnection(url,sid,dbuser,dbpass,dbdriver,dbport,dbhost);
context.setAttribute("database", conn);

How Can I still be able to populate my drop down with this Arrangement or Do I need to change Anything?

Upvotes: 0

Views: 155

Answers (1)

ZanoOnStack
ZanoOnStack

Reputation: 409

You could try to use Session

session = request.getSession();

Upvotes: 1

Related Questions