急!!jsp+servlert+prototype1.5+ajax返回值问题
我需要的效果是,当servlert处理完以后,test.jsp页面中ID为showit的DIV显示输入的结果(这只是一个测试程序,所以流程简单,请不要说可以就用JS在客户端实现)。但是我每次servlert处理完了以后,页面上还是显示数据处理,也就是说AJAX的状态没有一直没有到200.请问如何解决,很急,谢谢各位大大了!
自己也指导servlert处理数据是无返回值的,但是就是不懂,AJAX中XMLHTTPRequest这个对象是怎么处理这样的情况的!?
test.jsp:
<script language="JavaScript" type="text/JavaScript" src="myjs/prototype.js"></script>
<script language="JavaScript" type="text/JavaScript"><!--
//此处是我的表单处理函数本函数无错,所以不贴出
function setPostBody(_form){
。。。。}
//此处是AJAX提交函数
function posttest(){
var url = 'Test';//servlertname
var ajax = new Ajax.Request(url,{
method: 'post',
contentType: 'application/x-www-form-urlencoded',
encoding: 'UTF-8',
postBody: setPostBody($('mytest')),
onLoading: function(){
$("showit").innerHTML = "正在处理数据...";
},
onSuccess: function(){
$("showit").innerHTML= request.responseText;
}
});
}
--></script>
<form name="mytest" onSubmit="posttest();return false;">
<div>
<input type="text" id="tname" name="tname"/>
<input type="text" id="tother" name="tother"/>
<input type="submit" id="but" value="submit"/>
</div>
</form>
<div id = "showit"></div>
我是本楼主,继续刚才没发完的...
servlert代码如下:
package dreamtime.dreamnews;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: TestServlet
*
* @web.servlet
* name="TestServlet"
* display-name="TestServlet"
* description="test"
*
* @web.servlet-mapping
* url-pattern="/TestServlet"
*
* @web.servlet-init-param
* name="getValue"
* value="1"
* description="test"
*
*/
public class TestServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#HttpServlet()
*/
public TestServlet() {
super();
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/* (non-Java-doc)
* @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8"); //设置编码方式为GBK
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
System.out.println("start");
out.println("<p>");
out.println(request.getParameter("tname"));
out.println("</p>");
out.println("<p>");
out.println(request.getParameter("tother"));
out.println("</p>");
System.out.println(request.getParameter("tname"));
System.out.println(request.getParameter("tother"));
System.out.println("end");
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答 2007-08-22
提交路径不对吧
你Servlet里写的不是 TestServlet 吗
Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答