导入jar包"
import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionContext;
通过代码获得浏览器的信息:
HttpServletRequest request = (HttpServletRequest)ActionContext.getContext().get(org.apache.struts2.StrutsStatics.HTTP_REQUEST);
String userAgent = request.getHeader("User-Agent");
下面是userAgent 打印的信息也就是浏览器的信息:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)