Is there anything available in the HttpServletRequest which would tell me whether the request came through HTTP or WAP originally, letting me set my content type on the response accordingly? I want something a bit more reliable than the user-agent in the header.

Edward Williams

Since submitting this I have found out the solution myself - or at least one solution, there are probably others. The answer lies in "accept" part of the header. Basically, if it contains the directive for WAP and WML then the content type of the response can be set for WML.

i.e.

/** Content type string for HTML */
public static final String CONTENT_TYPE_HTML = "text/html";

/** Content type string for WML */
public static final String CONTENT_TYPE_WML = "text/vnd.wap.wml";

/** The header which contains the available content types. */
public static final String HEADER_ACCEPT = "accept";

/** Returns a content type based on the requesting content type
* @param request Servlet request object
* @return The content type
*/
public static String getContentType( HttpServletRequest request ) {

String retval = CONTENT_TYPE_HTML; // Default return.

if (null != request) {
String mimeTypes = request.getHeader( HEADER_ACCEPT );
if ( null != mimeTypes ) {
if ( 0 != mimeTypes.trim().length() ) {
if ( -1 != mimeTypes.toLowerCase().indexOf(CONTENT_TYPE_WML) ) {
retval = CONTENT_TYPE_WML;
}
// Put any other content type conversions in here.
}
}
}

return retval;
}

This will set the content type to HTML by default, unless the user agent accepts WML.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact