• Post Reply Bookmark Topic Watch Topic
  • New Topic

Achiving the browser compatibility using Java Filters

 
Swapnil Narkar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am facing a weired problem, We have application developed in Java 5 and it is best viewed with IE8.
Now we want to render the same application pages using IE10.

We have implemented following filter for the same but it does not work in IE10.

Any help is appriciated.

below is the code

public final class IE10CompatibilityFilter implements Filter
{

public void destroy() {
// TODO Auto-generated method stub

}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

String userAgentStr =((HttpServletRequest)request).getHeader("User-Agent");
if (userAgentStr != null && (userAgentStr.contains("MSIE 9.0") || userAgentStr.contains("MSIE 10.0") || userAgentStr.contains("MSIE 11.0"))){
//Might not be required, but doesn't hurt either
ServletRequest wrappedRequest = new WrapperRequest((HttpServletRequest)request);
((HttpServletResponse)response).setHeader("X-UA-Compatible", "IE=EmulateIE8");
chain.doFilter(wrappedRequest, response);
}
else {
chain.doFilter(request, response);
}
}


private class WrapperRequest extends HttpServletRequestWrapper {
public WrapperRequest(HttpServletRequest request) {
super(request);
}
public String getHeader(String name) {
//get the request object and cast it
HttpServletRequest request = (HttpServletRequest)getRequest();
if("user-agent".equalsIgnoreCase(name)) {
return "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0)";
}
return request.getHeader(name);
}
}



public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub

}

}
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the "if" condition being triggered when it should?
 
Swapnil Narkar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No . It is not. Even if we remove the if condition and return the mentioned string, it does not work
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35743
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does "doesn't work" mean? Is the filter getting called and the headers are being ignored? Or is the filter not even being called?
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may be relevant: http://atomiccode.wordpress.com/2013/04/15/problems-with-ie-10-and-x-ua-compatible-meta-tag/ (and if a cursory reading gives the right impression, then the time may have come for you to make your web app *actually* compatible with current browsers, instead of *pretend* compatible).
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:then the time may have come for you to make your web app *actually* compatible with current browsers, instead of *pretend* compatible

Quoted for emphasis. It's almost 2014 -- the time to be writing and supporting web apps that only run (or only run well) in antiquated and soon-to-be-unsupported browsers is long since passed. The decision makers at your organization need to realize this now; not later.
 
Swapnil Narkar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The filter is getting called but the pages are not displayed properly. Also this application is legacy application which was the older version of the product and the current version is supported in the latest browsers.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the header is being added, but the browser is still not correctly rendering the pages, there's likely not much you can do. After all, the header doesn't really make anything compatible, it's just a hint to the browser that the page contains older non-standard code.

If there's a more up-to-date version of the app, it's likely time to migrate the legacy users to it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!