Filter - ServletContext

2003-02-27 Thread Günter Kukies
Hello,

I want to read some context-param from web.xml within a filter. But the getAttribute 
is always null. 
There is no problem to get the same context-param within a Servlet.


Thanks

Günter 

Here is the code snippet:


import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.sql.*;
import javax.sql.*;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import javax.naming.*;

public class MyFilter implements Filter {

// The filter configuration object we are associated with.  If
// this value is null, this filter instance is not currently
// configured.
private FilterConfig filterConfig = null;
String category_server_ip = ;
int category_server_port = 8080;
String category_root = ;
String category_base = ;
/**
 * Init method for this filter
 *
 */
public void init(FilterConfig filterConfig) {

this.filterConfig = filterConfig;
ServletContext sctx = filterConfig.getServletContext();
sctx.getServletContextName();
category_server_ip = (String)sctx.getAttribute(category_server_ip);
category_server_port = 
stringToInt((String)sctx.getAttribute(category_server_port));
category_root = (String)sctx.getAttribute(category_root);
category_base = (String)sctx.getAttribute(category_base);
if (filterConfig != null) {
if (debug) {
log(MyFilter :Initializing filter);
}
}
}

public MyFilter () {

}
.


Re: Filter - ServletContext

2003-02-27 Thread Jon Wingfield
Try:

sctx.getInitParameter(...) instead of sctx.getAttribute(...)

Günter Kukies wrote:

Hello,

I want to read some context-param from web.xml within a filter. But the getAttribute is always null. 
There is no problem to get the same context-param within a Servlet.

Thanks

Günter 

Here is the code snippet:

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.naming.*;

public class MyFilter implements Filter {
   
   // The filter configuration object we are associated with.  If
   // this value is null, this filter instance is not currently
   // configured.
   private FilterConfig filterConfig = null;
   String category_server_ip = ;
   int category_server_port = 8080;
   String category_root = ;
   String category_base = ;
   /**
* Init method for this filter
*
*/
   public void init(FilterConfig filterConfig) {
   
   this.filterConfig = filterConfig;
   ServletContext sctx = filterConfig.getServletContext();
   sctx.getServletContextName();
   category_server_ip = (String)sctx.getAttribute(category_server_ip);
   category_server_port = stringToInt((String)sctx.getAttribute(category_server_port));
   category_root = (String)sctx.getAttribute(category_root);
   category_base = (String)sctx.getAttribute(category_base);
   if (filterConfig != null) {
   if (debug) {
   log(MyFilter :Initializing filter);
   }
   }
   }
   
   public MyFilter () {
   
   }
   .

 





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Filter - ServletContext

2003-02-27 Thread Erik Price


Günter Kukies wrote:
Hello,

I want to read some context-param from web.xml within a filter. But the getAttribute is always null. 
There is no problem to get the same context-param within a Servlet.


Don't you want getInitParameter() ?



Erik

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Filter - ServletContext

2003-02-27 Thread Günter Kukies
Oh, sorry getInitParameter() was the solution. Thanks for your hint.
But why is the ServletContext not the same in Filter and HTTPServlet?

Günter

- Original Message -
From: Erik Price [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Thursday, February 27, 2003 4:54 PM
Subject: Re: Filter - ServletContext




 Günter Kukies wrote:
  Hello,
 
  I want to read some context-param from web.xml within a filter. But the
getAttribute is always null.
  There is no problem to get the same context-param within a Servlet.


 Don't you want getInitParameter() ?




 Erik


 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Filter - ServletContext

2003-02-27 Thread Erik Price


Günter Kukies wrote:
Oh, sorry getInitParameter() was the solution. Thanks for your hint.
But why is the ServletContext not the same in Filter and HTTPServlet?
I am confused.  There is one ServletContext in a webapp (as far as I 
know, which isn't very far).  You can access it from a Filter using 
getFilterConfig().getServletContext(), and you can access it from a 
HttpServlet using getServletContext().  It is the same.



Erik

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]