John Topley's Knowledgebase

Using The Struts Logic Tag To Detect Browser Version

Monday, 01 December 2003

The Jakarta Struts <logic:match> tag can be used to detect the version of the web browser being used to view the page. The tag performs a case-insensitive substring search using the value specified. This enables the User-Agent string in the HTTP header to be queried for the browser version.

The code given below displays “Microsoft Internet Explorer 6.0” if running IE 6.0, or “Opera” or “Mozilla” if running any version of those browsers.

Download 0031.txt

  • The JSP:
<logic:match header="User-Agent" value="IE">
  <logic:match header="User-Agent" value="6.0">
    <p>Microsoft Internet Explorer 6.0</p>
  </logic:match>
</logic:match>
<logic:match header="User-Agent" value="Opera">
  <p>Opera</p>
</logic:match>
<logic:match header="User-Agent" value="Mozilla">
  <p>Mozilla</p>
</logic:match>

top | index | previous | next | comments ()

home | archive | kb | media | about | contact | accessibility
Copyright © 2003 - 2005 John Topley. Made with CityDesk.