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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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 theuser-agentheader 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.So, this should do:
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
mediaattribute. E.g.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.