Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-03-2008, 11:09 PM
Member
 
Join Date: Apr 2008
Posts: 1
samiahmed is on a distinguished road
i need help for ServletContext
hello everybody Actually i'm trying to type a ServletContext but i Got the following Error

MyListener.java:25: contextDestroyed(javax.servlet.ServletContextEvent ) in MyLis
tener cannot implement contextDestroyed(javax.servlet.ServletContextEvent ) in ja
vax.servlet.ServletContextListener; overridden method does not throw java.lang.E
xception
public void contextDestroyed(ServletContextEvent sce)throws Exception
^
MyListener.java:13: contextInitialized(javax.servlet.ServletContextEve nt) in MyL
istener cannot implement contextInitialized(javax.servlet.ServletContextEve nt) i
n javax.servlet.ServletContextListener; overridden method does not throw java.la
ng.Exception
public void contextInitialized(ServletContextEvent sce) throws Exception

^
2 errors


and my code is

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletContext.*;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public final class MyListener implements ServletContextListener
{
Connection con;
public void contextInitialized(ServletContextEvent sce) throws Exception
{

ServletContext ctx=sce.getServletContext();
String dburl=ctx.getInitParameter("dburl");
String uname=ctx.getInitParameter("uname");
String pwd=ctx.getInitParameter("pwd");
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("dburl,uname,pwd") ;
ctx.setAttribute("Connection",con);

}
public void contextDestroyed(ServletContextEvent sce)throws Exception
{

ServletContext ctx=sce.getServletContext();
con=(Connection)ctx.getAttribute("Connection");
con.close();
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 01:21 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org