ajax 没反应

来源:百度知道 编辑:UC知道 时间:2024/06/01 12:08:46
我的servlet
package ajax;

@SuppressWarnings("serial")
public class ajaxaction extends HttpServlet{
@Override
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
doPost(arg0, arg1);}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
res.setContentType("text/xml; charset=GBK");
PrintWriter out = res.getWriter();
String name = req.getParameter("username");
if(name.equalsIgnoreCase("hunter"))
out.print(1);
out.flush();
out.close();
}
}
〉〉〉〉〉〉〉jsp
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>ajax</title>
</head>
<body bgcolor="#ffffff">
<h1>
<

看是不是路径问题?
req.open("post","ajax/ajaxa",true);
换成
req.open("post","/ajaxa",true); 试试

没有反映? 你确定servlet被调用了吗,加断点之后运行,再就是是否有多个ajax去访问同一个servlet,如此的话需要清理ie缓存