Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get browser information in JSP?

Tags:

jsp

How do you get Client IP and Browser information using JSP?

like image 764
vipin k. Avatar asked Sep 03 '09 12:09

vipin k.


People also ask

How to check browser in JSP?

To find out what browser and/or OS the user is using, parse the user-agent header. For a list of user agents, look here. Show activity on this post. For the browser part you need to parse the reqeust's User-Agent section.

How do you tell which browser a user is using?

To detect user browser information we use the navigator. userAgent property. And then we match with the browser name to identify the user browser. Now call this JS function on page load, and this will display the user browser name on page load.


2 Answers

The following jsp will output your ip address and user-agent:

Your user-agent is: <%=request.getHeader("user-agent")%><br/>
Your IP address is: <%=request.getRemoteAddr()%><br/>

To find out what browser and/or OS the user is using, parse the user-agent header.

For example:

<%
String userAgent = request.getHeader("user-agent");
if (userAgent.indexOf("MSIE") > -1) {
  out.println("Your browser is Microsoft Internet Explorer<br/>");
}
%>

For a list of user agents, look here.

like image 61
D. Wroblewski Avatar answered Nov 12 '22 09:11

D. Wroblewski


For the browser part you need to parse the reqeust's User-Agent section.

String browserType = request.getHeader("User-Agent");

There you'll find the relevant information...

like image 42
KB22 Avatar answered Nov 12 '22 10:11

KB22