• 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

implements ServletContextListener in weblogic 8.1

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 814
Java Linux
 
Sourav Mukherji
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any body write down the steps how to implement it?
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic