Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Restricting access to jsp pages in Filters

    Hi ,
    I am using a filter to prevent direct access to jsp pages (everything works fine). But I have 2 pages that should not be "filtered" when the url is given.
    Like the welcome.jsp page . When the user gives welcome.jsp page it should not be forwarded to the login.jsp page (I am redirecting all the other jsp pages to login.jsp page) .
    I dont want to hard code it using if () stmts in the filter.
    Please provide me the solution so tht when the user enters the welcome.jsp , he is directed to welcome.jsp page instead of login.jsp page.
    Is there any way to do it in the web.xml.
    thanks

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    you could specify the pages u want to be ignored by the filter in the form of initialization parameters which can be specified in web.xml
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    tech99sri (04-27-2008)

  • #3
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts

    how do I specify the initialization parameters in the web.xml

    Hello Shyam ,
    Thanks for the reply.
    How do I specify these jsp pages in the web.xml .
    Can u please provide me the sample code .
    Where do I need to initialize the parameters (is tht inside the filter declaration ??) .
    Please provide the solution

  • #4
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Code:
      <filter>
        <filter-name>my-filter</filter-name>
        <filter-class>org.foo.bar.MyFilter</filter-class>
        <init-param>
          <param-name>allow-without-auth</param-name>
          <param-value>/welcome.jsp</param-value>
        </init-param>
      </filter>
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    tech99sri (04-28-2008)

  • #5
    New Coder
    Join Date
    Apr 2008
    Posts
    17
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Filter in web.xml (initialising the jsp pages)

    Hi Shyam ,
    I made the changes you suggested in the web.xml , but the filer still filters the welcome.jsp and redirects to the login.jsp page .
    Do I need to add any code anywhere other than the web.xml (I just added the
    <init-param>
    <param-name>allow-without-auth</param-name>
    <param-value>/welcome.jsp</param-value>
    </init-param> in the web.xml )

    this is my web.xml --

    <filter>
    <filter-name>filter</filter-name>
    <filter-class>
    RedirectFilter
    </filter-class>
    <init-param>
    <param-name>allow-without-auth</param-name>
    <param-value>/welcome.jsp</param-value>
    </init-param>
    </filter>
    <filter-mapping>
    <filter-name>filter</filter-name>
    <servlet-name>RedirectFilter</servlet-name>

    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <!-- <url-pattern>*.jsf</url-pattern> -->
    </filter-mapping>

    <filter-mapping>
    <filter-name>filter</filter-name>
    <url-pattern>*.jsf</url-pattern>
    </filter-mapping>

    ----
    ---

    Please help me solve this prob
    thanks

  • #6
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    just adding the init-param isn't gonna magically do anything...you've to code in the Filter to take appropriate action based on the specified params
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •