An example value for pattern is (?:Mozilla[^\(]*\(compatible;\s*+([^;]*);.*)|(?:.*?([^\s]+/[^\s]+).*)
. These two
pattern match the common compatibility user-agent strings and extract the real user agent, failing that, the first
element of the agent string is returned.
- Author:
- gregw
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
UserAgentFilter
public UserAgentFilter()
destroy
public void destroy()
- Specified by:
destroy
in interface Filter
doFilter
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException,
ServletException
- Specified by:
doFilter
in interface Filter
- Throws:
IOException
ServletException
init
public void init(FilterConfig filterConfig)
throws ServletException
- Specified by:
init
in interface Filter
- Throws:
ServletException
getUserAgent
public String getUserAgent(ServletRequest request)
getUserAgent
public String getUserAgent(String ua)
- Get UserAgent.
The configured agent patterns are used to match against the passed user agent string.
If any patterns match, the concatenation of pattern groups is returned as the user agent
string. Match results are cached.
- Parameters:
ua
- A user agent string
- Returns:
- The matched pattern groups or the original user agent string