File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes BEA/Weblogic and the fly likes implements ServletContextListener in weblogic 8.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » BEA/Weblogic
Bookmark "implements ServletContextListener in weblogic 8.1" Watch "implements ServletContextListener in weblogic 8.1" New topic
Author

implements ServletContextListener in weblogic 8.1

Sourav Mukherji
Greenhorn

Joined: Jun 19, 2010
Posts: 2
How to solve the problem?
is it run through weblogic 8.1?

The problem is bellow:

I create a class file: bellow the code

import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class dataConn implements ServletContextListener {

Connection con;
public void contextInitialized(ServletContextEvent sce) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("Jdbc:Odbc:test123","test","pass");//for mysql
}
catch(Exception ex) {
//out.println("Error");
}
sce.getServletContext().setAttribute("Connection",con);
}
public void contextDestroyed(ServletContextEvent sce) {
try {
con.close( );
}
catch(Exception ex) {
}
}
}

I call the class file through jsp, the jsp code is bellow

<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>

<%
String mempid="";
String mempname="";
%>
<%!
Connection con=null;
ResultSet rs1=null;
PreparedStatement ps=null;
%><head>
</head>
<%
try {
con=(Connection)getServletContext().getAttribute("Connection");
ps=con.prepareStatement("select empid,empname FROM emp_mast");
rs1=ps.executeQuery();
while(rs1.next()){
mempid=rs1.getString("empid");
mempname=rs1.getString("empname");
out.println(mempid+" "+mempname+"<br>");
}
}catch(Exception ex1){
}

%>

I add a listner in web.xml -

<listener>
<listener-class>
dataConn
</listener-class>
</listener>

and place the class in class folder

It runs well at tomcat 5.5 server

but when i want to run weblogic 8.1 , it shows error in
con=(Connection)getServletContext().getAttribute("Connection");of my jsp
getServletContext() - ERROR : no method with this name could be found at this location
How to solve the problem?
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Welcome to JavaRanch

UseCodeTags


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Sourav Mukherji
Greenhorn

Joined: Jun 19, 2010
Posts: 2
can any body write down the steps how to implement it?
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787





I am not sure but just compare j2ee specification followed by weblogic 8.1 and tomcat 5.5 and also check required jars are available or not.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: implements ServletContextListener in weblogic 8.1
 
Similar Threads
NULL POINTER eXCEPTION
Problem using Tomcat's crossContext
JavaMAIL Configuration Error
calling a bean object from a servlet into a plain java class
ServletContextListener Class fails