xmlHttp.open不调用Servlet
1)jsp页面functionwindow.onbeforeunload(){varsubmitUrl="ajaxReq?teller=111111";alert("此方...
1)jsp页面
function window.onbeforeunload() {
var submitUrl ="ajaxReq?teller=111111";
alert("此方法在关闭网页时自动调用的");
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST",submitUrl,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = func;
xmlHttp.send();
}
}
function func() {
}
2)web.xml
<servlet>
<servlet-name>loginOut</servlet-name>
<display-name>loginOut</display-name>
<servlet-class>itp.busi.login.loginOut</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginOut</servlet-name>
<url-pattern>/ajaxReq</url-pattern>
</servlet-mapping>
3)java代码
package itp.busi.login;
public class LoginOut extends HttpServlet {
private static final long serialVersionUID = 1L;
public void init() throws ServletException{}{
//输出日志
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
//输出日志
String teller_no = request.getParameter("teller");
//调用其他方法
//输出日志
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
//输出日志
}
public void destroy() {
//输出日志
}
}
执行jsp的时候未调用上述java方法,求解,急 展开
function window.onbeforeunload() {
var submitUrl ="ajaxReq?teller=111111";
alert("此方法在关闭网页时自动调用的");
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("POST",submitUrl,true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = func;
xmlHttp.send();
}
}
function func() {
}
2)web.xml
<servlet>
<servlet-name>loginOut</servlet-name>
<display-name>loginOut</display-name>
<servlet-class>itp.busi.login.loginOut</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>loginOut</servlet-name>
<url-pattern>/ajaxReq</url-pattern>
</servlet-mapping>
3)java代码
package itp.busi.login;
public class LoginOut extends HttpServlet {
private static final long serialVersionUID = 1L;
public void init() throws ServletException{}{
//输出日志
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
//输出日志
String teller_no = request.getParameter("teller");
//调用其他方法
//输出日志
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
//输出日志
}
public void destroy() {
//输出日志
}
}
执行jsp的时候未调用上述java方法,求解,急 展开
展开全部
是什么浏览器,一般用javascript初始化xmlHttpRequest时判断浏览器,因为IE跟其他浏览器的实现方式不一样。
if(window.ActiveXObject) // IE浏览器
{
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest) // 除IE以外的其他浏览器
{
xmlHttpRequest = new XMLHttpRequest();
}
if(window.ActiveXObject) // IE浏览器
{
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest) // 除IE以外的其他浏览器
{
xmlHttpRequest = new XMLHttpRequest();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询