How to access request header attributes using JSTL

To access request header using jstl you will have to include the funcations taglib as below (assuming jstl jars are already in the project classpath)

<%@ taglib prefix="fn" uri=""%>

The syntax is as below


So in your JSP code you can do something like this

    <c:when test="${fn:contains(header['user-agent'], 'MSIE')}">
        You're using Internet Explorer.
        You are using some browser other than IE.

The jstl code inside test=”…” checks if your ‘user-agent’ is Internet Explorer and shows message accordingly.

Caution: Please do not mix scriplets and jstl tags in jsp. They do not run in same scope and hence tend to cause problems. The golden rule is “AVOID SCRIPLETS IN JSP”.


, , ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: