====index.jsp========
<%@ page pageEncoding="GBK" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<script>
var thread;
var isfirst = true;
function upload(){
try{
document.forms[0].submit();
}catch(exception){
alert(exception.name);
}
p.style.display = '';
thread = window.setInterval("startmove()",100);
var my = document.getElementByIdx("up");
isfirst = false;
}
var w = 1;
var flag = 'right';
function startmove(){
if(flag == 'right'){
w += 2;
if(w>95){
w = 95;
flag = 'left';
}
}else{
w -= 1;
if(w<1){
flag = 'right';
id1.width = '';
return;
}
}
id1.width = w + '%';
}
function stopmove(){
window.clearInterval(thread);
p.style.display = "none";
if(!isfirst){
getResult();
}
w = 1;
}
var req;
var url = 'http://localhost:8080/webtest/msg.jsp';
function getResult() {
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, false);
req.send(null);
alert( req.responseText);
}
</script>
</head>
<body>
<div id="p" style="display:none">
<table width="572" height="30" border="0" cellspacing="0" cellpadding="0">
<tr align="left">
<td id="id1" width="0" bgcolor="#999999"/>
<td id="id2" width="5%" bgcolor="#0033FF"/>
<td id="id3" width="95%" bgcolor="#999999"/>
</tr>
</table>
</div>
<br>
<form action = "something.jsp" enctype="multipart/form-data" method="post" target="up">
<input name="file" type="file" >
<input type="button" onClick="upload()" value="提交" />
</form>
<% System.out.println("aaaa"); %>
<p><br>
<span id="msg"></span>
</p>
<iframe style="display:none" οnlοad="stopmove()" name="up"></iframe>
</body>
</html>
====== something.jsp======
<%@ page contentType="text/html; charset=GBK" %>
<%
response.setHeader("Cache-Control", "no-cache");
Thread.sleep(5000);//do something
System.out.println(">>>>");
session.setAttribute("msg","上传成功!");
%>
===== msg.jsp=====
<%@ page contentType="text/html; charset=GBK" %>
<%
String msg = (String)session.getAttribute("msg");
System.out.println("msg:"+msg);
if(msg == null)
out.write("");
else{
out.write(msg);
}
%>