• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Filter authentication won't display error page

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using a filter to verify a user exists in a list of groups before displaying the page.

If a user fails the verification filter they get sent to an error page.
The problem is the error page can't find my images, it will show the text on the page though. It seems the mappings get screwed up and being forwarded. How can I correct this?

Thanks.
Dave
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The problem is the error page can't find my images


Suppose we restate the problem as "the browser can't find the images as my IMG tags are presently written."

Perhaps your error page needs to include a BASE tag to give a path to where the server has the images.
Bill
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can change the error page so that it knows the absolute location of the images eg "/"+getContext()+"/images/error.jpg"
 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems like my filter-mapping is not allowing access to the images???
Is there a value to only check classes/jsp's and exclude everything else such as images?
Thanks Again,
Dave

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Bosky:
It seems like my filter-mapping is not allowing access to the images???
Is there a value to only check classes/jsp's and exclude everything else such as images?
Thanks Again,
Dave




The problem is that your mapping is intercepting every call to the server, including requests for static files.
You should never use /*.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
<hr></blockquote>


The problem is that your mapping is intercepting every call to the server, including requests for static files.
You should never use /*.[/QB]



[almost never]
 
Sheriff
Posts: 28411
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, shouldn't use /*. So what's the url-pattern for "all servlets and JSPs"? Right now I'm using /* and my filter contains code to accept images and CSS files.
 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What code did you add to your filter to accept/ignore image/css files?

Thanks,
Dave
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
Okay, shouldn't use /*. So what's the url-pattern for "all servlets and JSPs"? Right now I'm using /* and my filter contains code to accept images and CSS files.



I did go back and add "almost never".


A better way to say it would have been:
Never use /* unless you really want to intercept EVERY request to the server.
 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I resolved the issue by adding an init-param to the filter config.


Thanks,
Dave
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a suggestion regarding your code - just a minor change for greater efficiency. You are parsing the extensions string over and over againg for every request, although it could be done just once, at filter initialization. Besides, if you put all the extensions into a map, you would be able to find out if the requested resource is static simply by doing a lookup.

private Map excludedExtensionsMap = new HashMap();

public void init(FilterConfig cfg) throws ServletException {
String extensions = cfg.getInitParameter("ExcludedExtensions");
if (extensions != null) {
StringTokenizer st = new StringTokenizer(extensions, ",");
while (st.hasMoreTokens()) {
excludedExtensionsMap.put(st.nextToken().trim(), ""); // only the key matters here
}
}
}

// in doFilter()

boolean isStaticResource = false;

String path = request.getServletPath();
int pos = path.lastIndexOf(".");
if (pos >= 0) {
String ext = path.substring(pos + 1);
isStaticResource = excludedExceptionsMap.containsKey(ext);
}

// the rest of your filter logic

Don't get me wrong: this piece of code alone won't win you any noticeable gain in performance, but I am just making a point here: small code optimizations here and there can add up to substantial amounts of saved processor ticks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic