Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a java application identify a specific browser?

How can I identify whether the browser is Firefox or Chrome? Basically, I want an application to run only on the specific browser that is registered by a user. For this scenario, I want my application to identify the browser which the user is using, to know whether the application is permitted to run.

I am using java servlet.

I tried a the browser’s local storage, but it can be deleted with no control from my application. If local storage can be used, please let me know how.

(Yes I can get a browser info, but I want to identify a specific machine with a browser from where my application user is permitted to run the application; otherwise, I need to restrict that user from accessing my application.)

like image 823
Swap L Avatar asked Sep 16 '25 05:09

Swap L


2 Answers

Fetch user-agent properties from the HTTP requeste header.

  String userAgent=req.getHeader("user-agent");
  String browserName = "";
  String  browserVer = "";
  if(userAgent.contains("Chrome")){ //checking if Chrome
        String substring=userAgent.substring(userAgent.indexOf("Chrome")).split(" ")[0];
        browserName=substring.split("/")[0];
        browserVer=substring.split("/")[1];
    }
    else if(userAgent.contains("Firefox")){  //Checking if Firefox
        String substring=userAgent.substring(userAgent.indexOf("Firefox")).split(" ")[0];
        browserName=substring.split("/")[0];
        browserVer=substring.split("/")[1];
    }
like image 115
Alpesh Gediya Avatar answered Sep 18 '25 19:09

Alpesh Gediya


httpRequest.getHeader("user-agent")
like image 39
Mustafa Genç Avatar answered Sep 18 '25 18:09

Mustafa Genç