×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Karthick Bala
Added: Jul 25, 2014 10:00 AM
Views: 6
Tags: no tags
  1.     public static String getAcceptTypeFromReq(HttpServletRequest request){
  2.         String acceptHdr = (String)request.getHeader("Accept");
  3.         String userAgent = (String)request.getHeader("User-Agent");
  4.         String mimeType = "json";//No I18N
  5.         if (acceptHdr != null && acceptHdr.indexOf("application/xhtml+xml") != -1) {
  6.             mimeType = "html";//No I18N
  7.         }else if (acceptHdr != null && acceptHdr.indexOf("application/xml") != -1) {
  8.             mimeType = "xml";//No I18N
  9.         }else if(acceptHdr != null && (acceptHdr.equals("application/json"))){
  10.             mimeType = "json";//No I18N
  11.         }else if(acceptHdr != null && (acceptHdr.equals("zohoforms/urllist+json"))){
  12.             mimeType = "json";//No I18N
  13.         }
  14.         // IE's accept header won't contain the term "html". In order to render "403 Forbidden" page as html, the below check is included.
  15.         else if(userAgent != null && (userAgent.toLowerCase()).indexOf("msie") != -1 && acceptHdr != null && acceptHdr.indexOf("application/xaml+xml") != -1) {
  16.             mimeType = "html";//No I18N
  17.         }
  18.         return mimeType;
  19.        
  20.     }