我做了一个删除功能,删除后不刷新页面用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(" 批次:"+chi.getBatch()+" 录入日期"+chi.getDate());
out.
println(" 雏鸡编号:"+chi.getChicklingNumber()+" ");
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>
批次:<%=chi.getBatch() %> 录入日期:<%=chi.getDate() %> 雏鸡编号:<%=chi.getChicklingNumber() %>
<a href="UserLogin/ChicklingInfoManagement/UpDate.jsp?choice=<%=i%>" target=_blank>修改</a>
<a href="" onclick="doRequest(<%=i%>)">删除</a><br>
<%
}%></div>
不过我在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(" 批次:"+chi.getBatch()+" 录入日期"+chi.getDate());
out.
println(" 雏鸡编号:"+chi.getChicklingNumber()+" ");
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>
批次:<%=chi.getBatch() %> 录入日期:<%=chi.getDate() %> 雏鸡编号:<%=chi.getChicklingNumber() %>
<a href="UserLogin/ChicklingInfoManagement/UpDate.jsp?choice=<%=i%>" target=_blank>修改</a>
<a href="" onclick="doRequest(<%=i%>)">删除</a><br>
<%
}%></div>
解决方案 »
- 如何分步显示???????????????????????????????急求解
- jsp使用flash控件实现上传图片
- 求JBoss+Apache的整合方法
- 100求购!jfreechart的API文档
- 求助! 有谁做过定时器的, 时间可以自由设定的,急啊~
- 请赐教:给俺推荐几本JSP教材!!谢谢
- Oracle的性能怎么都用不上的?
- ant与web.xml配置问题
- 如何配置localhost的二级域名?例如http://test.localhost
- springMvc+mybatis 存储过程中有mysql inout属性参数,用mybatis 注解如何调用,注意是注解不是xml
- Jsp编译中出现 '.' expected 错误
- 关于权限的设计问题(急用)各位高手帮帮忙!先谢过
无论在哪个页面,一点击都是回到首页...晕死.不知道什么问题
alert(xhr.responseText);
if (responseDiv.hasChildNodes()) {
responseDiv.removeChild(responseDiv.childNodes[0]);
}
alert("Set response");
responseDiv.innerHTML=xhr.responseText;这里面的两个alert都正常显示出来了.action返回来的字符都正常.
但是就是会自动返回.
在filter里测试过了,没有进到filter里.很奇怪这是怎么了