How to get browser information in JSP?

How do you get IP client and browser information using JSP?

+6
jsp
source share
6 answers

For part of the browser, you need to analyze the User-Agent reqeust section.

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

There you will find relevant information ...

+5
source share

The following jsp will print 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 which browser and / or OS the user is using, analyze the header of the user agent.

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, see here .

+11
source share

ServletRequest.getRemoteAddr () or X-Forwarded-For if you think you can trust it.

What browser information? Request headers will have a User-Agent.

+1
source share
 String browser=request.getHeader("user-agent"); String browsername = ""; String browserversion = ""; String[] otherBrowsers={"Firefox","Chrome","Chrome","Safari"}; if(browser != null ){ if((browser.indexOf("MSIE") == -1) && (browser.indexOf("msie") == -1)){ for(int i=0; i< otherBrowsers.length; i++){ System.out.println(browser.indexOf(otherBrowsers[i])); browsername=otherBrowsers[i]; break; } String subsString = browser.substring( browser.indexOf(browsername)); String Info[] = (subsString.split(" ")[0]).split("/"); browsername = Info[0]; browserversion = Info[1]; } else{ String tempStr = browser.substring(browser.indexOf("MSIE"),browser.length()); browsername = "IE" browserversion = tempStr.substring(4,tempStr.indexOf(";")); } } 
+1
source share

Here you can find getRemoteAddr (), which

Returns the full name of the client or last proxy that sent the request

... and with this you can (possibly) get a browser

 request.getHeader("User-Agent") 
0
source share

You can get all the information that the client is ready to provide you through HTTP headers. Here is their complete list.

To access the header in a servlet or JSP, use:

request.getHeader ("header-of-what-you-want");

0
source share