页面刷新问题 我完成一个动作,完成之后想通过js把页面部分自动刷新,请问怎么实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用AJAX,给你个原生的小例子吧<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@ taglib prefix="s" uri="/struts-tags" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'show.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script language="javascript"> //定义一个变量用于存放XMLHttpRequest对象 var xmlHttp; //改函数用于创建一个XMLHttpRequest对象 function createXMLHttpRequest(){ if(window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } } //这是一个启动AJAX异步通信的方法 function getServerTime(){ var now = new Date();//获取系统当前的时间 //创建一个XMLHttpRequest对象 createXMLHttpRequest(); //将状态触发器绑定到一个函数 xmlHttp.onreadystatechange= processServerTime; //通过GET方法向指定的URL建立服务器的调用,加个临时的参数,以便表示一个全新的请求 var url="getServerTime?tmp="+now.getTime();//等写完回来看这一句话 xmlHttp.open("GET",url,true); //发送请求 xmlHttp.send(null); } //这是一个用来处理状态改变的函数 function processServerTime(){ //定义一个变量用于存放从服务器返回的响应结果 var responseContext; if(xmlHttp.readyState==4){ //如果响应成功 alert(xmlHttp.status); if(xmlHttp.status==200){ //取出服务器的响应内容 responseContext=xmlHttp.responseText; document.getElementById("servertime").innerHTML=responseContext; } } } /**以上是获取当前时间的**/ //这是一个启动AJAX异步通信的方法 function ajaxLogin(){ var ln = document.getElementById("loginname").value; var lp = document.getElementById("loginpwd").value; //创建一个XMLHttpRequest对象 createXMLHttpRequest(); //将状态绑定到一个函数 xmlHttp.onreadystatechange=processAjaxLogin; //通过GET方法向指定的URL建立服务器的调用 var url="ajax_ajaxLogin.action?loginname="+ln+"&loginpwd="+lp; xmlHttp.open("GET",url,true); //发送请求 xmlHttp.send(null); } //这是一个用来处理状态改变的函数 function processAjaxLogin(){ //定义一个变量用于存放 从服务器返回的响应结果 var responseContext=""; if(xmlHttp.readyState==4){ if(xmlHttp.status==200){ responseContext = xmlHttp.responseText; alert(xmlHttp.responseText=="登录成功"); alert(responseContext.substring(0, 4)=="登录成功"); alert(responseContext.substring(0, 4).length); document.getElementById("loginresult").innerHTML=responseContext; } } } </script> </head> <body><table border="1"> <tr> <th> 1.服务器端的系统时间: </th> <td colspan="2"> <input type="button" value="获取服务器端时间" onclick="getServerTime()"> </td> <td colspan="2"> <span id="servertime"></span> </td> </tr> <tr> <th align="left"> 2.登陆账号: </th> <td> <input type="text" id="loginname" name="loginname"> </td> <th> 登陆密码: </th> <td> <input type="password" id="loginpwd" name="loginpwd"> </td> <td> <div id="loginresult"></div> </td> </tr> <tr> <td> <input type="button" value="异步登陆" onclick="ajaxLogin()"> </td> </tr></table></body></html>不过要用到struts2 还有问题的话继续问 完成操作之后,进入之前显示此页面的action,就相当于刷新了当前页面了... 用AJAX。在请求成功的回调函数里更新你要更新的页面(DOM)内容就可以了 JAX-RS(RESTLET API)与Spring的集成,有没有集成两者经验的没有? oracle查询出的数据顺序问题 哪位高手 试过mongo+java ssh 开发 单选按钮的名字是可改变的 怎么获取他的参数啊 让oracle中让纵表打成横表怎么打? 在ORACLE中查找XML数据(在线等待) 哇哇哇哇新问题!!!!!!!!! 各位帮兄弟的忙哟!关于java程序的乱码问题. 急!!!!!!!!!能告诉我几个java连接数据库的步骤!!给分 如何用Java在xml文档中插入一个节点?能否给个例子!谢谢! 求教 一段wsdl该怎么传输 myeclipse6.0编译不了
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'show.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script language="javascript">
//定义一个变量用于存放XMLHttpRequest对象
var xmlHttp;
//改函数用于创建一个XMLHttpRequest对象
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
}
//这是一个启动AJAX异步通信的方法
function getServerTime(){
var now = new Date();//获取系统当前的时间 //创建一个XMLHttpRequest对象
createXMLHttpRequest();
//将状态触发器绑定到一个函数
xmlHttp.onreadystatechange= processServerTime;
//通过GET方法向指定的URL建立服务器的调用,加个临时的参数,以便表示一个全新的请求
var url="getServerTime?tmp="+now.getTime();//等写完回来看这一句话
xmlHttp.open("GET",url,true);
//发送请求
xmlHttp.send(null);
} //这是一个用来处理状态改变的函数
function processServerTime(){
//定义一个变量用于存放从服务器返回的响应结果
var responseContext;
if(xmlHttp.readyState==4){
//如果响应成功
alert(xmlHttp.status);
if(xmlHttp.status==200){
//取出服务器的响应内容
responseContext=xmlHttp.responseText;
document.getElementById("servertime").innerHTML=responseContext;
}
}
}
/**以上是获取当前时间的**/ //这是一个启动AJAX异步通信的方法
function ajaxLogin(){
var ln = document.getElementById("loginname").value;
var lp = document.getElementById("loginpwd").value;
//创建一个XMLHttpRequest对象
createXMLHttpRequest(); //将状态绑定到一个函数
xmlHttp.onreadystatechange=processAjaxLogin;
//通过GET方法向指定的URL建立服务器的调用
var url="ajax_ajaxLogin.action?loginname="+ln+"&loginpwd="+lp;
xmlHttp.open("GET",url,true); //发送请求
xmlHttp.send(null);
}
//这是一个用来处理状态改变的函数
function processAjaxLogin(){
//定义一个变量用于存放 从服务器返回的响应结果
var responseContext="";
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
responseContext = xmlHttp.responseText;
alert(xmlHttp.responseText=="登录成功");
alert(responseContext.substring(0, 4)=="登录成功");
alert(responseContext.substring(0, 4).length);
document.getElementById("loginresult").innerHTML=responseContext;
}
}
}
</script>
</head>
<body><table border="1">
<tr>
<th>
1.服务器端的系统时间:
</th>
<td colspan="2">
<input type="button" value="获取服务器端时间" onclick="getServerTime()">
</td>
<td colspan="2">
<span id="servertime"></span>
</td>
</tr>
<tr>
<th align="left">
2.登陆账号:
</th>
<td>
<input type="text" id="loginname" name="loginname">
</td>
<th>
登陆密码:
</th>
<td>
<input type="password" id="loginpwd" name="loginpwd">
</td>
<td>
<div id="loginresult"></div>
</td>
</tr>
<tr>
<td>
<input type="button" value="异步登陆" onclick="ajaxLogin()">
</td>
</tr>
</table>
</body>
</html>
不过要用到struts2 还有问题的话继续问