Ajax XMLHttpRequest invokes servlet doFilter or not
我正在尝试从如下所示的jsp页面进行ajax调用,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <head> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET","ajax_info.txt", true); xmlhttp.send(); document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } </head> <body> <button type="button" onclick="loadXMLDoc()">Change Content</button> </body> |
这是第一次调用servlet过滤器,但是在ajax调用期间,我看不到doFilter被调用。
过滤器的URL映射针对到服务器的所有传入请求都映射为*。
为什么这里没有为Ajax调用调用Servlet过滤器?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <head> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState === 4 && xmlhttp.status === 200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } xmlhttp.open("GET","ajax_info.txt", true); xmlhttp.send(); } </head> <body> <button type="button" onclick="loadXMLDoc()">Change Content</button> </body> |
使用