Detecting Wireless Clients in a JSP or Servlet

You can write a JSP or servlet that services requests from wireless phones and Web browsers at the same time, especially when you are handling form input. When you send a response back, of course, you want to know whether you should send HTML or WML. When the browser or the phone makes a request, it passes the Web server a list of the kinds of content it will accept. You can retrieve the list by making the following method call:

String accept = request.getHeader("Accept");

For a wireless client, you should see text/vnd.wap.wml somewhere in the accept string. You can test for it this way:

 if (accept.indexOf("text/vnd.wap.wml") >= 0) { // handle a wireless client } else { // handle a regular Web ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.