我做了一个删除功能,删除后不刷新页面用JS刷新层里的内容就行.但是不知道为什么一删除就跳转回了首页.很郁闷.我哪也没有设置这个跳转.
不过我在web.cml里设了一个session过滤器,session空的话就跳回首页.但是要进入到删除信息页面是要登录的,也就是session不会为空.很奇怪.请大家帮我看看.
Struts的配置文件
<action
      input="/UserLogin/ChicklingInfoManagement/Display.jsp"
      path="/delChickling"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy">
      <forward name="ok" path="/UserLogin/ChicklingInfoManagement/Display.jsp" />
    </action>
Action里的部分代码,我想用循环输出集合中的信息:
response.setContentType("text/xml");
response.setCharacterEncoding("UTF-8");
PrintWriter out=null;
try {
out = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


for(int i=0;i<list.size();i++){
chi=(Chickling)list.get(i);
out.
print("雏鸡名称:<a href='UserLogin/ChicklingInfoManagement/DisplaySingleOne.jsp?choice=");
out.
println(i+"'"+" target=_blank>"+chi.getChicklingName() +"</a>");
out.
print("&nbsp;批次:"+chi.getBatch()+"&nbsp;录入日期"+chi.getDate());
out.
println("&nbsp;雏鸡编号:"+chi.getChicklingNumber()+"&nbsp;");
out.
print("<a href='UserLogin/ChicklingInfoManagement/UpDate.jsp?choice='"+i );
out.
println("target=_blank>修改</a>");
out.
print("<a href="+request.getContextPath()+"/delChickling.do>删除</a><br>");


}out.flush();
out.close();
return null;
页面的JS代码:var xhr;
    var outMsg = ""
    function createXMLHttpRequest() {
        if (window.ActiveXObject) {
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest) {
            xhr = new XMLHttpRequest();
        }
    }
    function createQueryString(id) {
        var queryString = "choice=" + id;
        return queryString;
    }
    function doRequest(id) {
        createXMLHttpRequest();
        var queryString = "delChickling.do?";
        queryString = queryString + createQueryString(id);
        xhr.onreadystatechange = handleStateChange;
        alert("Before do");
        xhr.open("POST", queryString, true);
        xhr.setRequestHeader("Content-Type",
                "application/x-www-form-urlencoded");
        xhr.send(null);
    }
    function handleStateChange() {
        if (xhr.readyState == 4) {
            if (xhr.status == 200) {
                parseResults();
            }        }
    }
    function parseResults() {
        var responseDiv = document.getElementById("Layer4");
        
        
        if (responseDiv.hasChildNodes()) {
            responseDiv.removeChild(responseDiv.childNodes[0]);
        }    
        responseDiv.innerHTML=xhr.responseText;
    }
页面的层代码:<div id="Layer4" align="left"><%
for(int i=0;i<list.size();i++){
Chickling chi=(Chickling)list.get(i);
%>
雏鸡名称:<a href="UserLogin/ChicklingInfoManagement/DisplaySingleOne.jsp?choice=<%=i%>" target=_blank><%=chi.getChicklingName() %></a>
&nbsp;批次:<%=chi.getBatch() %>&nbsp;录入日期:<%=chi.getDate() %>&nbsp;雏鸡编号:<%=chi.getChicklingNumber() %>&nbsp;
<a href="UserLogin/ChicklingInfoManagement/UpDate.jsp?choice=<%=i%>" target=_blank>修改</a>
<a href="" onclick="doRequest(<%=i%>)">删除</a><br>
<%

}%></div>

解决方案 »

  1.   

    还有我其他页面做了"返回"功能的超连接onclick="history.back()",
    无论在哪个页面,一点击都是回到首页...晕死.不知道什么问题
      

  2.   

            var responseDiv = document.getElementById("Layer4");
            
            alert(xhr.responseText);
                if (responseDiv.hasChildNodes()) {
                responseDiv.removeChild(responseDiv.childNodes[0]);
            }    
            alert("Set response");
            responseDiv.innerHTML=xhr.responseText;这里面的两个alert都正常显示出来了.action返回来的字符都正常.
    但是就是会自动返回.
    在filter里测试过了,没有进到filter里.很奇怪这是怎么了