日期:2014-05-19 浏览次数:20669 次
public class fuck extends ActionSupport{
@Override
public String execute() throws Exception {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter out = response.getWriter();
System.out.println("-----------------");//为什么这个执行了,控制台却不会输出?
out.print(1); //这个值始终传不到页面。
out.flush();
out.close();
return SUCCESS;
}
}
<script type="text/javascript">
function CheckUser(){
req = new XMLHttpRequest();
alert("------");
req.open("post","/dcfs/denglu");
req.send();
req.onreadystatechange=req_onreadystatechange;
}
function req_onreadystatechange(){
if(req.readyState==4)
{
alert(req.readyState);
alert(req.responseText); //这里打印的是HTML页面的代码
}
}
</script>
</head>
<body>
<input type="button" id="but" name="but" value="Ajax测试" onclick="return CheckUser()"/>
</body>
<package name="Album" namespace="/" extends="struts-default">
<action name="denglu" class="action.fuck">
<result name="success">/index.jsp</result>
</action>
</package>
var xmlHttp = getRequest();
var url = "indexAction.jsp?date="+(new Date());
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = function(){
if (xmlHttp.readyState == 4) {
var response = xmlHttp.responseText;
document.getElementById("hello").innerText = response;
}
};
xmlHttp.send(null);