0

I need a servlet code that would return the type of client browser and detect if there is a PDF Viewer plug-in installed on it.

I've tried using HttpServletRequest's available .getHeader("User-Agent") like the following :

String userAgent = request.getHeader("user-agent");

But it only returns the following browser types and no plug-ins :

"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; InfoPath.2)"

Is there any way that I could detect a PDF Viewer plug-in inside a servlet?

Any answer would be greatly appreciated. Thank you very much!

kazeopeia
  • 15
  • 1
  • 7

1 Answers1

0

You can't do this in a servlet and for sure not based on the user agent. Your best bet is performing the detection in a language which runs in the webbrowser itself, for example JavaScript. There are several JavaScript solutions around, see for example the comments and the answer of this question javascript detect adobe reader plugin for browser.

To pass this information from JavaScript to the Servlet, you could pass a request parameter by either ajax or manipulating a hidden field in a form, or set a cookie and then check it in the servlet. Request parameters and cookies are available by the usual HttpServletRequest methods.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555