Servlet filter problem

I've written a simple servlet filter to intercept a request to another servlet. So when the user tries to access /servlet/ViewMetadata servlet, they first hit InterceptServlet, the filter configured in Tomcat.
I need to access the name and URL of the target servlet ViewMetada within InterceptServlet but don't know how to do this. I am familiar with HttpServletRequest.getServletPath() but doFilter uses ServletRequest as its argument.
Can I obtain the target servlet name inside the filter servlet? I know this is probably very basic!
Arc

If the filter is invoked by a HttpServletRequest, then the ServletRequest handle you've in the filter is just an instance of HttpServletRequest.
Cast it back.

Similar Messages

  • 10.1.3 EA3 Visual editor & servlet filter problem

    I have a problem with jsp visual editor after I add filter servlet into web.xml file.
    When I chage view of visual editor to Design page I can't see page preview.
    I enable "Show design time messages in log" option, I get the following messages in log:
    Error exercising tag : afh:head
    java.lang.NullPointerException
         at oracle.adfinternal.view.faces.renderkit.AdfRenderingContext.getTranslatedString(AdfRenderingContext.java:70)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.GlobalVariablesScriptlet.outputScriptletContent(GlobalVariablesScriptlet.java:49)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.Scriptlet.outputScriptletImpl(Scriptlet.java:111)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.Scriptlet.outputScriptlet(Scriptlet.java:52)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.XhtmlUtils.addLib(XhtmlUtils.java:124)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.Scriptlet.outputDependency(Scriptlet.java:144)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.AliasedScriptlet.outputScriptletImpl(AliasedScriptlet.java:113)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.Scriptlet.outputScriptlet(Scriptlet.java:52)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.XhtmlUtils.addLib(XhtmlUtils.java:124)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.Scriptlet.outputDependency(Scriptlet.java:144)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.DefaultTimeZoneScriptlet.outputScriptletImpl(DefaultTimeZoneScriptlet.java:41)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.jsLibs.Scriptlet.outputScriptlet(Scriptlet.java:52)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.XhtmlUtils.addLib(XhtmlUtils.java:124)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.HeadRenderer._writeCookieScript(HeadRenderer.java:124)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.HeadRenderer.encodeBegin(HeadRenderer.java:72)
         at oracle.adfinternal.view.faces.renderkit.core.CoreRenderer.encodeBegin(CoreRenderer.java:139)
         at oracle.adf.view.faces.component.UIXComponentBase.encodeBegin(UIXComponentBase.java:593)
         at javax.faces.webapp.UIComponentTag.encodeBegin(UIComponentTag.java:591)
         at oracle.adf.view.faces.webapp.UIXComponentTag.encodeBegin(UIXComponentTag.java:108)
         at javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:478)
         at oracle.adf.view.faces.webapp.UIXComponentTag.doStartTag(UIXComponentTag.java:85)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.doStartTag(DesignTimeJspActionRenderer.java:1313)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer._executeTag(DesignTimeJspActionRenderer.java:1634)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.render(DesignTimeJspActionRenderer.java:241)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.render(FacesActionRenderer.java:127)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderer.renderChildren(DesignTimeRenderer.java:424)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.renderChildren(DesignTimeJspActionRenderer.java:772)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.renderChildren(FacesActionRenderer.java:367)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer._executeTag(DesignTimeJspActionRenderer.java:1665)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.render(DesignTimeJspActionRenderer.java:241)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.render(FacesActionRenderer.java:127)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderer.renderChildren(DesignTimeRenderer.java:424)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.renderChildren(DesignTimeJspActionRenderer.java:772)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.renderChildren(FacesActionRenderer.java:367)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer._executeTag(DesignTimeJspActionRenderer.java:1665)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.render(DesignTimeJspActionRenderer.java:241)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.render(FacesActionRenderer.java:127)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderer.renderChildren(DesignTimeRenderer.java:424)
         at oracle.jdevimpl.webapp.jsp.renderers.JSPCoreSyntaxRenderer.render(JSPCoreSyntaxRenderer.java:66)
         at oracle.jdevimpl.webapp.design.support.jsp.DesignTimeJspServlet._renderSource(DesignTimeJspServlet.java:197)
         at oracle.jdevimpl.webapp.design.support.jsp.DesignTimeJspServlet.serviceJsp(DesignTimeJspServlet.java:109)
         at oracle.jdevimpl.webapp.design.support.jsp.DesignTimeJspServlet.service(DesignTimeJspServlet.java:73)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletInfo.service(DesignTimeServletInfo.java:268)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher.dispatch(DesignTimeRequestDispatcher.java:197)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher.forward(DesignTimeRequestDispatcher.java:72)
         at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         at oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:157)
         at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletInfo.service(DesignTimeServletInfo.java:268)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher$DesignTimeFilterChain.doFilter(DesignTimeRequestDispatcher.java:307)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher.dispatch(DesignTimeRequestDispatcher.java:193)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletContainerContext._service(DesignTimeServletContainerContext.java:611)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletContainerContext.service(DesignTimeServletContainerContext.java:570)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderThread.runImpl(DesignTimeRenderThread.java:264)
         at oracle.jdevimpl.webapp.design.DesignTimeThread.run(DesignTimeThread.java:146)
    Error exercising tag : afh:body
    java.lang.NullPointerException
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.BodyRenderer._writeVersionInformation(BodyRenderer.java:416)
         at oracle.adfinternal.view.faces.renderkit.core.xhtml.BodyRenderer.encodeAll(BodyRenderer.java:65)
         at oracle.adfinternal.view.faces.renderkit.core.CoreRenderer.encodeEnd(CoreRenderer.java:159)
         at oracle.adf.view.faces.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:624)
         at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:623)
         at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:546)
         at oracle.adf.view.faces.webapp.UIXComponentTag.doEndTag(UIXComponentTag.java:100)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.doEndTag(DesignTimeJspActionRenderer.java:1345)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer._executeTag(DesignTimeJspActionRenderer.java:1692)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.render(DesignTimeJspActionRenderer.java:241)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.render(FacesActionRenderer.java:127)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderer.renderChildren(DesignTimeRenderer.java:424)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.renderChildren(DesignTimeJspActionRenderer.java:772)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.renderChildren(FacesActionRenderer.java:367)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer._executeTag(DesignTimeJspActionRenderer.java:1665)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.render(DesignTimeJspActionRenderer.java:241)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.render(FacesActionRenderer.java:127)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderer.renderChildren(DesignTimeRenderer.java:424)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.renderChildren(DesignTimeJspActionRenderer.java:772)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.renderChildren(FacesActionRenderer.java:367)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer._executeTag(DesignTimeJspActionRenderer.java:1665)
         at oracle.jdevimpl.webapp.design.renderer.DesignTimeJspActionRenderer.render(DesignTimeJspActionRenderer.java:241)
         at oracle.jdevimpl.webapp.design.renderer.FacesActionRenderer.render(FacesActionRenderer.java:127)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderer.renderChildren(DesignTimeRenderer.java:424)
         at oracle.jdevimpl.webapp.jsp.renderers.JSPCoreSyntaxRenderer.render(JSPCoreSyntaxRenderer.java:66)
         at oracle.jdevimpl.webapp.design.support.jsp.DesignTimeJspServlet._renderSource(DesignTimeJspServlet.java:197)
         at oracle.jdevimpl.webapp.design.support.jsp.DesignTimeJspServlet.serviceJsp(DesignTimeJspServlet.java:109)
         at oracle.jdevimpl.webapp.design.support.jsp.DesignTimeJspServlet.service(DesignTimeJspServlet.java:73)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletInfo.service(DesignTimeServletInfo.java:268)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher.dispatch(DesignTimeRequestDispatcher.java:197)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher.forward(DesignTimeRequestDispatcher.java:72)
         at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
         at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:130)
         at oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:157)
         at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
         at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletInfo.service(DesignTimeServletInfo.java:268)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher$DesignTimeFilterChain.doFilter(DesignTimeRequestDispatcher.java:307)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeRequestDispatcher.dispatch(DesignTimeRequestDispatcher.java:193)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletContainerContext._service(DesignTimeServletContainerContext.java:611)
         at oracle.jdevimpl.webapp.design.support.http.DesignTimeServletContainerContext.service(DesignTimeServletContainerContext.java:570)
         at oracle.jdevimpl.webapp.design.DesignTimeRenderThread.runImpl(DesignTimeRenderThread.java:264)
         at oracle.jdevimpl.webapp.design.DesignTimeThread.run(DesignTimeThread.java:146)

    Hi all,
    Although I have removed filter mapping, the same problem described above continues except the exception messages are not exist now!
    Visual editor does not show any adf core components such as input text, tables rows etc.
    I'm using jdeveloper 10.1.3.0.4 newly so what is the problem?
    In source, I have used subview and tiles components. there may be problems because of usages of these components?
    At the beginning there was no problem, I could view the all components on visual designer...
    any idea... !?
    best regards
    --baris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Servlet Filter not working in Oracel9iAS(9.2.0.3)

    Hi,
    May i know what cause the servlet filter not workinng in Oracle9iAS? Is there any library files missing? I have tried deploy the war file in Tomcat but is working fine but when i try to deploy in Oracle9iAS, the application seems like can't call the servlet filter.
    Please advice.
    Thanks.
    Regards,
    Ming Jade

    I'm not exactly sure what version you are using.
    Servlet Filters were introduced in Servlet 2.3 which was part of J2EE 1.3.
    Oracle9iAS 9.0.2.3 is J2EE 1.2 compatible .
    Oracle Application Server 10g 9.0.4.x and 10.1.2 is J2EE 1.3 compatible
    Oracle Application Server 10g 10.1.3 is J2EE 1.4 compatible.
    So the problem could be that the version of the product you are using does does not support the version of the servlet spec that covers Servlet Filters.
    Can you upgrade to/install the 10.1.2 release as a minimum?
    cheers
    -steve-

  • Servlet Filter - for WL 5.1 (sp10) ?

    Hello All,
    we use WL 5.1 (sp10), on S.O. AIX.
    We want to filter some JSP pages (depending on the user), like an "Servlet Filter"
    (not present in WL 5.1, only 6.1 or superior) controling the "authorization".
    We know the feature "UrlAcl", but is not good for us.
    We recompiled the class JspBase (in package weblogic.servlet.jsp), including the
    wanted aditional feature "Filter servlet"; We tested it and it is ok and no problens
    ocorred.
    Now we have three questions:
    1- Does exits another solution to the problem above (filtering some JSP depending
    on the user)?
    2- My solution is good enought ? It´s normal to recompile the "internal classes
    of the weblogic" ?
    3- We want to send an email direct to BEA , but we don´t find a "contact" or web-form
    to send this question to BEA; Anyone has this email / information ?

    Hello All,
    we use WL 5.1 (sp10), on S.O. AIX.
    We want to filter some JSP pages (depending on the user), like an "Servlet Filter"
    (not present in WL 5.1, only 6.1 or superior) controling the "authorization".
    We know the feature "UrlAcl", but is not good for us.
    We recompiled the class JspBase (in package weblogic.servlet.jsp), including the
    wanted aditional feature "Filter servlet"; We tested it and it is ok and no problens
    ocorred.
    Now we have three questions:
    1- Does exits another solution to the problem above (filtering some JSP depending
    on the user)?
    2- My solution is good enought ? It´s normal to recompile the "internal classes
    of the weblogic" ?
    3- We want to send an email direct to BEA , but we don´t find a "contact" or web-form
    to send this question to BEA; Anyone has this email / information ?

  • Managed session bean in servlet filter

    Hi,
    Is there a way to get hold of a managed bean with session scope in a servlet filter? The code below throws an error due to the fact that the faces context is null.
    FacesContext facesContext = FacesContext.getCurrentInstance();
    System.out.println("facesContext: " + facesContext); // shows that facesContext is null
    ApplicationFactory appFactory = ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application app = appFactory.getApplication();
    Object obj = app.createValueBinding("user").getValue(facesContext); //throws the error due to the null parameter
    Object obj2 = app.createValueBinding("user"); //results in a valid ValueBindingHere is the faces-config snippet for the managed bean:
    <managed-bean>
        <managed-bean-name>user</managed-bean-name>
        <managed-bean-class>biz.libereco.skemo.info.asl.beans.User</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>For the record, I am using JSF 1.0 Final.
    Thank you,
    Marcel

    wynton_0 wrote:
    Yes, there is a way to get hold of a managed bean with session scope in a servlet filter.
    See here:
    [http://wiki.apache.org/myfaces/AccessFacesContextFromServlet]
    and here:
    [how to access faces context and backing beans in a servlet filter|http://www.thoughtsabout.net/blog/archives/000033.html]
    This makes no utter sense. A JSF session scoped managed bean is under the hood just put as a HttpSession attribute with the managed bean name as key. Guess what, you can just access the HttpSession in Filter by ((HttpServletRequest) request).getSession() and then just call getAttribute() on it. If it isn't there yet, then just do a setAttribute() with a new instance.
    After I get User bean in my Servlet filter, I populate value to this bean, for example:
    user.setLanguage(request.getParameter("locale"));
    The User bean is in session scope. The User bean's language attribute suppose to be same in the whole session scope, but later on, I got null. My question is:
    how to keep this value in session scope?The the session was apparently invalidated/renewed or you manually removed the bean or replaced it by null.
    In the future, please don't resurrect old topics, just start a new topic for each independent problem/question.

  • Null query string in servlet filter with OC4J 10.1.3.1.0

    I have a strange problem with OC4J 10.1.3.1.0. In the servlet filter, while requesting the querystring with HttpServletRequest.getQueryString the result is null, even if it is verified with a sniffer that that query string is there. This happens only with certain requests. The query string is long but nothing very special otherwise.
    Any ideas what might be wrong?
    Thanks,
    Mika

    I got the same problem. I tried in others application servers alternatives and it works. By now i have to change links like this "http://localhost:8888/SIVIUQ/LoadIndex.portal?test=1" for forms using javaScript to send the parameters corresponding to the button pressed. To use buttons instead links is not the better solution due to usability. Any suggestion to solve this problem?
    Thanks
    Javier Murcia
    Yo tengo el mismo problema. He intentado con otros servidores de aplicaciones y funciona. Por ahora tengo que cambiar links como "http://localhost:8888/SIVIUQ/LoadIndex.portal?test=1" por formularios, usando javaScript para enviar los parametros correspondientes al boton presionado. Usar botones en vez de links no es la mejor solucion debido a usabilidad. ¿Alguna sugerencia para resolver este problema?
    Gracias
    Javier Murcia

  • Request.setHeader in servlet filter

    Hi there,
    I am working on servlet filter to filter HttpServletRequest before sending it to the original servlet.
    The original servlet expects some content posted in the body of HttpServletRequest object.
    In my servlet filter, I need to modify this content (already done) and then doFilter to the origin.
    And here is the problem:
    The original servlet uses HTTP header's content-length value to read the entire content posted. But if I modify this content in my filter, it will never get correct content of the request.
    Unfortunately the original servlet is black boxed and there is no way to modify it.
    Is there any way to modify HTTP headers of HttpServletRequest in servlet filter?
    Thank you for any suggestions,
    mato_v

    Hum... ServletRequest.getHeader is read only, so you can't change them. There few solution you may try though:
    * Try create another wrapper instance of ServletRequest inside your filter and forward it to your black box servlet. You might have to wrote your own implementation to manipulate those Headers.
    * How about after you changed your data, redirect/post to your black box with the correct content? Use java.net.HttpURLConnection or a java Http client to do fancy posting if needed.
    Hope these helps.

  • Providing redirects in Servlet filter

    Hi,
    I need to provide serverside redirects in Servlet filter.O tried the below code, But unable to do it.
    Is it possible to do such a thing.
    public void doFilter(ServletRequest req, ServletResponse res,
                   FilterChain chain) throws IOException, ServletException {
              logger.info("Start of RedirectFilter ");
              HttpServletRequest request = (HttpServletRequest) req;
              HttpServletResponse response = (HttpServletResponse) res;
              String requestURI=request.getRequestURI();
              String domainURL=request.getServerName().toLowerCase();
              logger.info("domainName--"+domainName);
              String keywordToBeAppended=domainURL.replaceAll(domainName,"");
              logger.info("url--"+request.getRequestURI());
              logger.info("servername--"+request.getServerName());
              logger.info("keywordToBeAppended-"+keywordToBeAppended);
              String finalURL= request.getScheme()+"://"+domainURL+"/"+keywordToBeAppended+requestURI;
              logger.info("finalURL--"+finalURL);
              RequestDispatcher rd = request.getRequestDispatcher(finalURL);
              rd.forward(request, response);
              logger.info("End of RedirectFilter ");
              chain.doFilter(request, response);
         }

    There is technically a huge difference between "redirect" and "forward". You're doing here forwards. And because you continue the filter chain, you run into problems. You should do either a forward OR continuing the current request unchanged (through the filter chain) OR send a redirect. You cannot do one or more simultaneously.

  • How to embed servlet filter to an existing website

    I want to make an application using java servlet filters and I want to know the possibility of making this application as an add-on where anyone could take this application as it is and attach it to his website without knowing anything about servletes and with a very low programming or no programming effort, is it possible? If yes how and if no what is the alternative?

    836522 wrote:
    I really cant thank everyone enough for your help, thank you :)
    why not proxy? because I don't want the full functionalities of a proxy, so I thought why not to implement a servlet filter to do my task especially that all what I want to do could be easily implemented using the methods provided in servlets/filters. what I am thinking of now is to install servlet container and make it run in the proxy mode so any request to the website I want to protect will be directed first to the servlet then the servlet decide whether to pass this request to website or not, what do you think of this??I am afraid that will either not work or be overly complicated. The problem is with this
    so any request to the website I want to protect will be directed first to the servlet then the servlet decide whether to pass this request to website or notHow will the servlet pass on the request to the web site? Since it is not part of the other application, it cannot do a forward or include on the resource. Similarly a chain.doFilter() which is the normal way for the Filter to pass the request along to the end resource will not work.
    You can theorotically use a HttpClient from the Filter which will create a new http request to the underlying web site and flush the response received back to the browser. I think using a Proxy is the best bet. I would recommend an apache http server with some custom modules to implement your 'filter' code
    ram.

  • Strange behavior when using servlet filter with simple index.htm

    I am new to J2EE development so please tolerate my ignorance. I have a web application that starts with a simple index.htm file. I am using a servlet filter throughout the website to check for session timeout, redirecting the user to a session expiration page if the session has timed out. When I do something as simple as loading the index.htm page in the browser, the .css file and one image file that are associated, or referenced in the file are somehow corrupted and not being rendered. How do I get the filter to ignore css and image files??? Thank you!!
    The servlet filter:
    import java.io.IOException;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class SessionTimeoutFilter implements Filter {
         String[] excludedPages = {"SessionExpired.jsp","index.htm","index.jsp"};
         String timeoutPage = "SessionExpired.jsp";
         public void destroy() {
         public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
              if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
                   HttpServletRequest httpServletRequest = (HttpServletRequest) request;
                   HttpServletResponse httpServletResponse = (HttpServletResponse) response;
                   //httpServletResponse.setHeader("Cache-Control","no-cache");
                   //httpServletResponse.setHeader("Pragma","no-cache");
                   //httpServletResponse.setDateHeader ("Expires", 0);
                   String requestPath = httpServletRequest.getRequestURI();
                   boolean sessionInvalid = httpServletRequest.getSession().getAttribute("loginFlag") != "loggedIn";               
                   System.out.println(sessionInvalid);
                   boolean requestExcluded = false;
                   System.out.println(requestExcluded);
                   for (int i=0;i<excludedPages.length;i++){
                        if(requestPath.contains(excludedPages)){
                             requestExcluded = true;
                   if (sessionInvalid && !requestExcluded){
                        System.out.println("redirecting");
                        httpServletResponse.sendRedirect(timeoutPage);
              // pass the request along the filter chain
              chain.doFilter(request, response);
         public void init(FilterConfig arg0) throws ServletException {
              //System.out.println(arg0.getInitParameter("test-param"));
    The index.htm file (or the relevant portion)<HTML>
    <Head>
    <META http-equiv="Content-Style-Type" content="text/css">
    <LINK href="RTEStyleSheet.css" rel="stylesheet" type="text/css">
    <TITLE>Login</TITLE>
    </HEAD>
    <BODY>
    <FORM NAME="Login" METHOD="POST" ACTION="rte.ServletLDAP"><!-- Branding information -->
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
         <tr>
              <td width="30%" align="left"><img src="images/top_logo_new2.gif">
              </td>
              <td width="37%" align="center"></td>
              <td width="33%" align="right"></td>
         </tr>
    </table>
    My web.xml entry for the filter:     <filter>
              <description>
              Checks for a session timeout on each user request, redirects to logout if the session has expired.</description>
              <display-name>
              SessionTimeoutFilter</display-name>
              <filter-name>SessionTimeoutFilter</filter-name>
              <filter-class>SessionTimeoutFilter</filter-class>
              <init-param>
                   <param-name>test-param</param-name>
                   <param-value>this is a test parameter</param-value>
              </init-param>
         </filter>
         <filter-mapping>
              <filter-name>SessionTimeoutFilter</filter-name>
              <url-pattern>/*</url-pattern>
              <dispatcher>REQUEST</dispatcher>
              <dispatcher>FORWARD</dispatcher>
         </filter-mapping>

    Hi,
    Try adding CSS files and images to the excluded Pages.

  • Servlet Compilation Problem !

    Hi,
    I am just starting to learn servlets and I got problem in compiling them. I got compilation error in
    import javax.servlet.*;statement. Seems that the compiler cannot find the servlet package. I got J2EE 1.4 beta installed on my machine but there is no servlet.jar package. I am using J2SDK 1.4.1_02, J2EE 1.4 beta and Tomcat 4.1.24.
    Can anyone help me with my servlet compilation problem?
    Thanks in advance!
    Josh

    servlet.jar is here :
    <tomcatdir>\common\lib
    add it to your compiler classpath

  • Set Roles in servlet filter

    How can I set the user's role in the request object in a servlet filter
    so that in my action class, i can query the role using
    request.isUserInRole() and request.getUserPrinciple() methods.
    Any ideas...
    Thanks,

    How can I set the user's role in the request object
    in a servlet filter
    so that in my action class, i can query the role
    using
    request.isUserInRole() and request.getUserPrinciple()
    methods.You may want to check out JAAS in the Creator tutorial:
    http://developers.sun.com/prodtech/javatools/jscreator/ea/jsc2/reference/sampleapps/

  • Servlet chaining problem..

    import java.io.*;
        import javax.servlet.*;
        import javax.servlet.http.*;
        public class Deblink extends HttpServlet {
          public void doGet(HttpServletRequest req, HttpServletResponse res)
                                       throws ServletException, IOException {
            String contentType = req.getContentType();  // get the incoming type
            if (contentType == null) return;  // nothing incoming, nothing to do
            res.setContentType(contentType);  // set outgoing type to be incoming type
            PrintWriter out = res.getWriter();
            BufferedReader in = req.getReader();
            String line = null;
            while ((line = in.readLine()) != null) {
              line = replace(line, "<BLINK>", "");
              line = replace(line, "</BLINK>", "");
              out.println(line);
          public void doPost(HttpServletRequest req, HttpServletResponse res)
                                        throws ServletException, IOException {
            doGet(req, res);
          private String replace(String line, String oldString, String newString) {
            int index = 0;
            while ((index = line.indexOf(oldString, index)) >= 0) {
              // Replace the old string with the new string (inefficiently)
              line = line.substring(0, index) +
                     newString +
                     line.substring(index + oldString.length());
              index += newString.length();
            return line;
    What is pre request fo above code to work.
    I had tried this many time but it is not working, what will be calling servlet look like

    And can you explain why your title is "Servlet chaining problem"?

  • How to Add a Servlet Filter to Reports 11.1.1.2.0

    I am running Fusion Middleware 11g (Weblogic 10.3.2), with Oracle Forms/Reports 11.1.1.2.0. The installation is running the default managed servers WLS_FORMS and WLS_REPORTS.
    How can I add a Servlet Filter to the Reports 11.1.1.2.0 application which is running under the WLS_REPORTS managed server?
    I have read the Oracle Doc ID: 418366.1, which describes a process for adding a servlet filter to Reports Developer 10.1.2.2, but I am unclear as to which web.xml file I need to modify in weblogic and where to place the class file for the servlet filter.
    Thanks in advance for your help.

    I can provide some partial help.
    The set up I have was running it locally on Windows 7 (64 bit) laptop and running the reports server (version 11.1.1.4) in XP Mode as part of Windows 7 Professional.
    To find which web.xml file to change, I searched the directories for web.xml and then removed then renamed the web.xml files to something else to see which impacted the start up of the reports server.
    It turns out it was a web.xml file in web.war file in the following directory which impacted the start up:
    C:\Oracle\Middleware\user_projects\domains\ClassicDomain\servers\WLS_REPORTS\tmp\_WL_user\reports_11.1.1.2.0\1ww4ab
    So used winzip to extract files, update web.xml file and and java class as a jar file in the WEB-INF\lib directory and zipped back up to a web.war and put it in the above directory and restarted the Reports Server.
    Note the url pattern I used was slightly different to that shown in the oracle note (forward slash before asterix):
    <url-pattern>/rwservlet/*</url-pattern>
    Have not investigated how to do in for a production environment, but hopefully this information is of use.
    Les.

  • Memory leak in Servlet Filter handling?

    In Sun Web Server 6.1, I'm finding a memory leak when using servlet filters. I've even created a "no op" servlet filter. When it's registered, every 10000 hits or so to filtered static content will eat up about 5 to 10 MB of RAM. The JVM heap size doesn't increase.
    When I remove the filter, I've hit the same static page on the server 50000 times without seeing an increase in memory usage by the process.
    This is on Windows 2000, and I think the Sun Web Server 6.1 is SP1. I haven't tried SP2 yet.
    For reference, here's the filter I put in:
    public class NoOpFilter implements Filter
    public void init(FilterConfig arg0) throws ServletException {}
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    chain.doFilter(request, response);
    public void destroy() {}
    }

    I found the bug. I get the memory leak if magnus.conf has either or both of the following entries:
    AdminLanguage en
    DefaultLanguage en
    If I delete the entries, the memory leak goes away. I suppose this should get fixed by Sun sometime. Maybe I'll figure out how to officially report the bug later.

Maybe you are looking for

  • AS Button / hit state HELP!

    I have a clip with a hit state that I want to target frame 1 of another clip on mouseover. (thumbnail effect) There is a stop command on frame one of that secondary clip. On click , I want the secondary clip to play from frame 2, till the end. My pro

  • Premiere isn't in my Creative Cloud

    I wanted to download Premiere to test it but there was no Premiere (Pr)-App in my Cloud. There are a lot of programs but no Premiere. Yeah, I pressed "Show all apps", thats not the problem. Please help me!

  • MAM Profile Selection Variant

    Hi, I followed the configuration guide for MAM and created an Variant Operation for the Order Profile. Testing the variant (using IW37) it gives the correct amount of orders (5). Now using transaction SE37 to test MAM25_001, it gives me more orders t

  • Need advice for making a board layout in Ultiboard easy to assemble/troubleshoot

    I was wondering if anyone has a good method to go from a Multisim schematic to an Ultiboard layout, keeping specific legs of the circuit separated geographically for assembly and troubleshooting purposes.  I have a circuit with a few analog filters t

  • Need some help with tools for java projects

    Hi Friends, I just want to know what software release management tool do you use.Is there any free tool available on net?? I do not need a subversion tool( cvs,svn etc) or a automation build tool ( luntbuild, cruisecontrol, anthill) , I am looking fo