问题描述
我做了一个删除功能,删除后不刷新页面用JS刷新层里的内容就行.但是不知道为什么一删除就跳转回了首页.很郁闷.我哪也没有设置这个跳转.不过我在web.cml里设了一个session过滤器,session空的话就跳回首页.但是要进入到删除信息页面是要登录的,也就是session不会为空.很奇怪.请大家帮我看看.Struts的配置文件<actioninput="/UserLogin/ChicklingInfoManagement/Display.jsp"path="/delChickling"scope="request"type="org.springframework.web.struts.DelegatingActionProxy"><forwardname="ok"path="/UserLogin/ChicklingInfoManagement/Display.jsp"/></action>
Action里的部分代码,我想用循环输出集合中的信息:response.setContentType("text/xml");response.setCharacterEncoding("UTF-8");PrintWriterout=null;try{out=response.getWriter();}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}for(inti=0;i<list.size();i++){chi=(Chickling)list.get(i);out.print("雏鸡名称:<ahref='UserLogin/ChicklingInfoManagement/DisplaySingleOne.jsp?choice=");out.println(i+"'"+"target=_blank>"+chi.getChicklingName()+"</a>");out.print(" 批次:"+chi.getBatch()+" 录入日期"+chi.getDate());out.println(" 雏鸡编号:"+chi.getChicklingNumber()+" ");out.print("<ahref='UserLogin/ChicklingInfoManagement/UpDate.jsp?choice='"+i);out.println("target=_blank>修改</a>");out.print("<ahref="+request.getContextPath()+"/delChickling.do>删除</a><br>");}out.flush();out.close();returnnull;
页面的JS代码:varxhr;varoutMsg=""functioncreateXMLHttpRequest(){if(window.ActiveXObject){xhr=newActiveXObject("Microsoft.XMLHTTP");}elseif(window.XMLHttpRequest){xhr=newXMLHttpRequest();}}functioncreateQueryString(id){varqueryString="choice="+id;returnqueryString;}functiondoRequest(id){createXMLHttpRequest();varqueryString="delChickling.do?";queryString=queryString+createQueryString(id);xhr.onreadystatechange=handleStateChange;alert("Beforedo");xhr.open("POST",queryString,true);xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");xhr.send(null);}functionhandleStateChange(){if(xhr.readyState==4){if(xhr.status==200){parseResults();}}}functionparseResults(){varresponseDiv=document.getElementById("Layer4");if(responseDiv.hasChildNodes()){responseDiv.removeChild(responseDiv.childNodes[0]);}responseDiv.innerHTML=xhr.responseText;}
页面的层代码:<divid="Layer4"align="left"><%for(inti=0;i<list.size();i++){Chicklingchi=(Chickling)list.get(i);%>雏鸡名称:<ahref="UserLogin/ChicklingInfoManagement/DisplaySingleOne.jsp?choice=<%=i%>"target=_blank><%=chi.getChicklingName()%></a> 批次:<%=chi.getBatch()%> 录入日期:<%=chi.getDate()%> 雏鸡编号:<%=chi.getChicklingNumber()%> <ahref="UserLogin/ChicklingInfoManagement/UpDate.jsp?choice=<%=i%>"target=_blank>修改</a><ahref=""onclick="doRequest(<%=i%>)">删除</a><br><%}%></div>
解决方案
解决方案二:
麻烦大家帮忙看看啊
解决方案三:
还有我其他页面做了"返回"功能的超连接onclick="history.back()",无论在哪个页面,一点击都是回到首页...晕死.不知道什么问题
解决方案四:
varresponseDiv=document.getElementById("Layer4");alert(xhr.responseText);if(responseDiv.hasChildNodes()){responseDiv.removeChild(responseDiv.childNodes[0]);}alert("Setresponse");responseDiv.innerHTML=xhr.responseText;
这里面的两个alert都正常显示出来了.action返回来的字符都正常.但是就是会自动返回.在filter里测试过了,没有进到filter里.很奇怪这是怎么了