假设您正在编写Java
Web应用程序,我成功使用的一种技术是让访问的第一页(通常是登录表单)在页面加载时编写会话cookie。然后,获取表单提交的Java代码以检查该cookie的存在。
在客户端上:
<script type="text/javascript"> function createcookie(name, value, days) { var expires = ""; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } var cookie = name + "=" + value + expires + "; path=" + "/"; document.cookie = cookie; } createcookie("JavascriptEnabledCheck", 1, 0);</script>
在服务器上:
private boolean isJavascriptDisabled(HttpServletRequest request){ boolean isJavascriptDisabled = true; cookie[] cookies = request.getcookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if ("JavascriptEnabledCheck".equalsIgnoreCase(cookies[i].getName())) { isJavascriptDisabled = false; break; } } } return isJavascriptDisabled;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)