这是我的代码片断,有注释的,好读得很
testAjax_text.jsp=================================================
<script language=javascript>
//测试代码,现在只进行IE下的初始化,在以后的正式开发中,再进行通用性质的对象初始化
http_request = new ActiveXObject("Microsoft.XMLHTTP");
function doOnclick(){
//设置变更时的监听
http_request.onreadystatechange = onTextResponse;
//发送请求
var onClcikNumber = document.getElementById("onClcikNumber").value;
window.alert("/testAjax/testAjax_textAction.do?number="+onClcikNumber);
http_request.open("GET","testAjax_textAction.do?number="+onClcikNumber,true);
http_request.send(null);
}
//该方法用户当服务器正常响应并返回结果时,处理服务器的响应信息
function onTextResponse(){
if(http_request.readyState == 4 && http_request.status == 200){
//信息处理状态正确,开始处理信息
var textValue = http_request.responseText;
window.alert(textValue);
document.getElementById("mydiv").innerHTML = "您现在是第" + textValue + "次点击按钮";
}
}
</script><input type=button onclick="doOnclick()" value="点击此处">
<input type=hidden id="onClcikNumber" value="0">
<div id="mydiv">
</div>
//=====================================================配置文件的内容
<!-- test Ajax -->
<action path="/testAjax/testAjax_textAction" type="org.silverfly.struts.testajax.action.TestAjax_textAction" scope="request">
<forward name="suss" path="/testAjax/testAjax_text.jsp"></forward>
</action>
//action中的内容
/**
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
//开始接受信息
String number = request.getParameter("number") == null?"0":request.getParamete("number");
//开始回发响应
PrintWriter out = response.getWriter();
out.print((Integer.parseInt(number)) + 1);
out.close();
return actionMapping.findForward("suss");
}
//=============本来我是想返回一个数字的,结果ajax将testAjax_text.jsp中的所有内容全部返回给我了,大哥们,救命啊~~~~
testAjax_text.jsp=================================================
<script language=javascript>
//测试代码,现在只进行IE下的初始化,在以后的正式开发中,再进行通用性质的对象初始化
http_request = new ActiveXObject("Microsoft.XMLHTTP");
function doOnclick(){
//设置变更时的监听
http_request.onreadystatechange = onTextResponse;
//发送请求
var onClcikNumber = document.getElementById("onClcikNumber").value;
window.alert("/testAjax/testAjax_textAction.do?number="+onClcikNumber);
http_request.open("GET","testAjax_textAction.do?number="+onClcikNumber,true);
http_request.send(null);
}
//该方法用户当服务器正常响应并返回结果时,处理服务器的响应信息
function onTextResponse(){
if(http_request.readyState == 4 && http_request.status == 200){
//信息处理状态正确,开始处理信息
var textValue = http_request.responseText;
window.alert(textValue);
document.getElementById("mydiv").innerHTML = "您现在是第" + textValue + "次点击按钮";
}
}
</script><input type=button onclick="doOnclick()" value="点击此处">
<input type=hidden id="onClcikNumber" value="0">
<div id="mydiv">
</div>
//=====================================================配置文件的内容
<!-- test Ajax -->
<action path="/testAjax/testAjax_textAction" type="org.silverfly.struts.testajax.action.TestAjax_textAction" scope="request">
<forward name="suss" path="/testAjax/testAjax_text.jsp"></forward>
</action>
//action中的内容
/**
* @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
//开始接受信息
String number = request.getParameter("number") == null?"0":request.getParamete("number");
//开始回发响应
PrintWriter out = response.getWriter();
out.print((Integer.parseInt(number)) + 1);
out.close();
return actionMapping.findForward("suss");
}
//=============本来我是想返回一个数字的,结果ajax将testAjax_text.jsp中的所有内容全部返回给我了,大哥们,救命啊~~~~
解决方案 »
- JSTL for each 输出list 前台表格合并的问题
- 一个数字顺序问题。。大虾们看看吧
- 高手指点啊!!!我是这样用Jsp连接数据库的,为什么总是错啊???
- 各位大虾帮帮忙,看看我的JSP程序为什么没有打印出表格。结果只是将用户名排了出来,也没显示时间
- 自己写的一个小网站 www.yooche.com ,要学习spring hibernate或webwork的进来看看,高手就不要进来了
- session问题
- 请问如何在Applet中链接JSP或者Servlet
- JSP访问数据库异常???
- 请教问题
- 请问如何在XML字符串中传递中文
- 请问谁有《JSP动态网站开发基础练习+典型案例》这本书啊?急!
- 在文件夹下的所有BMP图片都要转换GIF图片 如何在JAVA类中转换
不论是改配置文件中的返回路径,还是在方法的最后改为return null,返回的全部是整个页面的代码
问题找到了哈,是因为myeclipse下的weblogic服务器插件的问题,重起以下就对了。谢谢各位