tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Günter Kukies <guenter.kuk...@heuft.com>
Subject Filter - ServletContext
Date Thu, 27 Feb 2003 12:05:57 GMT
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 () {
        
    }
    .....

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message