Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6157109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:43:47+00:00 2026-05-23T20:43:47+00:00

Im setting up a variable: <% String userAgent = request.getHeader(user-agent);%> How do I test

  • 0

Im setting up a variable:

<% String userAgent = request.getHeader("user-agent");%>

How do I test different scenarios against userAgent using

<c:choose></c:choose>

Im not sure how to set it up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:43:49+00:00Added an answer on May 23, 2026 at 8:43 pm

    You don’t want to mix scriptlets with taglibs/EL. They do not run in the same scope.

    All request headers are in EL available by an implicit mapped object ${header}. Since the user-agent header name contains a special character - so that ${header.user-agent} don’t work as expected, you need to use the brace notation [] which quotes it.

    ${header['user-agent']}
    

    So, this should do:

    <c:choose>
        <c:when test="${fn:contains(header['user-agent'], 'Gecko')}">
            You're pretending to use a Gecko based browser.
        </c:when>
        <c:when test="${fn:contains(header['user-agent'], 'MSIE')}">
            You're pretending to use a MSIE based browser.
        </c:when>
        <c:when test="${fn:contains(header['user-agent'], 'Webkit')}">
            You're pretending to use a Webkit based browser.
        </c:when>
        <c:otherwise>
            It's not clear which browser you're pretending to use.
        </c:otherwise>
    </c:choose>
    

    Unrelated to the problem: checking the user agent header this way is a code smell. The user agent header is fully controlled by the client and can easily be spoofed into a completely different value (that’s why I used the term “pretending” in the above code example). How to solve the real functional requirement properly, you’d like to elaborate a bit more about the real functional requirement.

    For example, in JavaScript you should prefer feature detection over browser detection.

    Or when you’d like to load specific stylesheets based on the media type, you should rather use the media attribute. E.g.

    <link rel="stylesheet" href="screen.css" media="screen,projection,tv" />
    <link rel="stylesheet" href="smartphone.css" media="only screen and (max-device-width:480px)"/>
    <link rel="stylesheet" href="handheld.css" media="handheld" />
    <link rel="stylesheet" href="print.css" media="print" />
    

    Or when you’d like to present the enduser an user-friendly summary of the information found in the user agent header, you’d like to use a separate service instead such as http://user-agent-string.info/. They also offer a Java API example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simply setting the SVN_EDITOR variable to mate does not get the job done. It
I am setting a string variable to the value of a input box in
I'm trying to save a string variable from my FolderBrowserDialog.SelectedPath(). Using a breakpoint I
I am setting a path variable with a query-string. What is the easiest way
How can I have a dynamic variable setting the amount of rows to return
I must be overlooking something simple. I'm setting a variable from a query result
I am having a problem setting the Authorize attribute Role value from a variable.
Setting up an integration server, I’m in doubt about the best approach regarding using
How can the string literal - ErrorLabel be replaced with string variable style in
I'm having trouble with setting a variable and then giving it the outcome of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.