Home > Back-end >  Java specify ie browser version by default
Java specify ie browser version by default

Time:12-01

Cause the
Projects are partly compatible ie11 version, ie browser open the default version of ie7 incompatible,
Target
Ie browser open 11 default version
ideas
Through the filter filter set request header to specify ie default kernel version
implementation code
Java filters

 

import java.io.IOException;
The import javax.mail. Servlet. The Filter;
The import javax.mail. Servlet. FilterChain;
The import javax.mail. Servlet. FilterConfig;
import javax.servlet.ServletException;
The import javax.mail. Servlet. ServletRequest;
The import javax.mail. Servlet. ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


Public class IECompatibilityFilter implements Filter {
Private FilterConfig FilterConfig=null;
String ieCompatible=null;


Public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
It the req=(it) request;
HttpServletResponse res=(HttpServletResponse)response;


If ((enclosing ieCompatible==null) | |
(this. IeCompatible. The trim (). EqualsIgnoreCase (" AUTO "))) {
String userAgent=the req. GetHeader (" the user-agent ");
If (userAgent!=null)
If (userAgent. The contains (" MSIE 7.0 "))
{
Res. SetHeader (" X-ray UA - Compatible ", "IE=EmulateIE7");
} else if (userAgent contains (" MSIE 8.0 "))
{
Res. SetHeader (" X-ray UA - Compatible ", "IE=EmulateIE8");
} else if (userAgent contains (" Trident/7.0 "))
{
Res. SetHeader (" X-ray UA - Compatible ", "IE=EmulateIE10");
} else if (this. IeCompatible==null)
{
Res. SetHeader (" X-ray UA - Compatible ", "IE=edge");
}
} else if (this. IeCompatible!=null) {
Res. SetHeader (" X-ray UA - Compatible ", enclosing ieCompatible);
}


Chain. DoFilter (the req, res);
}


Public void init (FilterConfig FilterConfig)
{
Enclosing the filterConfig=filterConfig;
If (this. FilterConfig!=null)
Enclosing ieCompatible=this. FilterConfig
GetInitParameter (" X - UA - Compatible ");
}


Public void destroy ()
{
}
}


Configuration specified ie browser version
Web.xml
 

IECompatibilityFilter

Com.jeecms.com mon. Filter. IECompatibilityFilter

X-ray UA - Compatible
IE=EmulateIE11 & lt;/param - value>
AUTO -->



IECompatibilityFilter
/* & lt;/url - pattern>




CodePudding user response:

to learn
  • Related