Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2008, 09:59 PM   PM User | #1
tech99sri
New Coder

 
Join Date: Apr 2008
Posts: 17
Thanks: 10
Thanked 0 Times in 0 Posts
tech99sri is an unknown quantity at this point
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
tech99sri is offline   Reply With Quote
Old 04-26-2008, 11:31 AM   PM User | #2
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
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
shyam is offline   Reply With Quote
Users who have thanked shyam for this post:
tech99sri (04-27-2008)
Old 04-27-2008, 03:23 AM   PM User | #3
tech99sri
New Coder

 
Join Date: Apr 2008
Posts: 17
Thanks: 10
Thanked 0 Times in 0 Posts
tech99sri is an unknown quantity at this point
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
tech99sri is offline   Reply With Quote
Old 04-27-2008, 05:31 AM   PM User | #4
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
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
shyam is offline   Reply With Quote
Users who have thanked shyam for this post:
tech99sri (04-28-2008)
Old 04-28-2008, 05:11 AM   PM User | #5
tech99sri
New Coder

 
Join Date: Apr 2008
Posts: 17
Thanks: 10
Thanked 0 Times in 0 Posts
tech99sri is an unknown quantity at this point
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
tech99sri is offline   Reply With Quote
Old 04-28-2008, 06:14 PM   PM User | #6
shyam
Senior Coder

 
shyam's Avatar
 
Join Date: Jul 2005
Posts: 1,563
Thanks: 2
Thanked 163 Times in 160 Posts
shyam will become famous soon enough
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
shyam is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:24 AM.


Advertisement
Log in to turn off these ads.