Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implements ServletContextListener in weblogic 8.1

 
Sourav Mukherji
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?
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
 
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: 802
Hibernate Linux Spring
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic