Jimmy Servlet
Jimmy Servlet

Reputation: 155

Showing UserAgent using JSP, how to shorten results? (I only want "firefox" or "chrome")

Im using JSP and Websphere to host a page that tells the user what browser they are using.

right now it says:

 Browser used to access this page is Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1)       Gecko/20100101 Firefox/10.0.1

but i want it to say just Firefox. does anyone know how i can do this?

heres my code for the java and h1:

 <% String userAgent = request.getHeader("User-Agent");%>
 <h1>Elon CSC430 Browser used to access this page is <%=userAgent%></h1>

Upvotes: 0

Views: 345

Answers (1)

Matt Harrison
Matt Harrison

Reputation: 358

As you have a String, can't you just use indexOf to check if Firefox is in the userAgent?

Or better yet, inject an object into the page that will do this determination (and checking for other browsers), and return the string you want put into the page, maybe?

Upvotes: 1

Related Questions