Connection Bean Instance Problem..
Hi,
I have a package ConnectionManager, I make an instance of it using <jsp:usebean id="CM" class="db.ConnectionManager" scope="request"/>
I am trying to call a global fuction in my jsp which returns a string. When I call path(someFilename) then this global function try to use instance CM by (CM.getConnection()) method. I am getting error here, I think my global function is not able to use the bean instance. Is there any other way to use the connection bean? What is the right approach? I can access my bean from jsp but not from a global function.
My Code:
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*,java.lang.Object.*"%>
<jsp:useBean class="db.ConnectionManager" scope="request" id="CM" />
<html>
<body>
<h1>Connection Manager Test</h1>
<%!
public String path(String filename){
Connection conn2 = CM.getConnection();
String template_path, strSQL;
Statement stmt = conn2.createStatement();
strSQL = "select t.path from ws_template as t join ws_page as p on t.id = p.template_id where p.path = '"+filename+"' and p.status >= 1000 and t.status >= 1000";
ResultSet rs = stmt.executeQuery(strSQL);
if (rs != null) {
while (rs.next()){
template_path = rs.getString("path");
}
}
else
{
}
rs.close();
conn2.close ();
return template_path;
}
%>
<%=path("About-Us")%>
</body>
</html>
My Error
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: -1 in the jsp file: null
Generated servlet error:
[javac] Compiling 1 source file
C:\tomcat\tomcat-4-1-18\work\Standalone\localhost\_\test_dbBean_jsp.java:18: cannot resolve symbol
symbol : variable CM
location: class org.apache.jsp.test_dbBean_jsp
Connection conn2 = CM.getConnection();
^
1 error

