用iframe进行文件异步上传时 函数回调一直不起作用即
用iframe进行文件异步上传时 函数回调一直不起作用即><br><span id="msg"></span>一直不起作用啊index.jsp<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function callback(msg){
document.getElementById("file").outerHTML =document.getElementById("file").outerHTML;
document.getElementById("msg").innerHTML = msg;
document.getElementById("path").value=msg; }
</script>
</head>
<body>
<form action="servlet/upLoad" method="post" enctype="multipart/form-data" target="uploadIframe">
添加附件:<input type="file" name="upload"/>
<input type="submit" value="上传"/><br><span id="msg"></span></form>
<iframe name="uploadIframe" id="uploadIframe" style="display:none"></iframe>
</body>
</html>
upLoad.java
package cat;
import java.io.*;
import java.util.Calendar;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.SmartUpload;
public class upLoad extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException{
this.config=config;
}
public String handleString(String s){
try{
byte bb[]=s.getBytes("iso-8859-1");
s=new String(bb);
}
catch(Exception ee){ee.printStackTrace();}
return s;
}
@SuppressWarnings({ "static-access" })
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=4000000;
String ext="";
String url="image/";//要保证在根目录中应该有此目录(自己建立相应的目录文件夹)
boolean sign = true;
mySmartUpload.initialize(config,request,response);
try{
mySmartUpload.setAllowedFilesList("jpg,gif");
mySmartUpload.upload();
com.jspsmart.upload.File myFile=mySmartUpload.getFiles().getFile(0);
ext=myFile.getFileExt();
int file_size=myFile.getSize();
String saveurl="";
if(file_size<file_size_max){
Calendar calendar=Calendar.getInstance();
String filename=String.valueOf(calendar.getTimeInMillis());
saveurl="D:/"+url;
File file=new File(saveurl);
if(!file.exists()){file.mkdir();}
saveurl+=filename+"."+ext;
myFile.saveAs(saveurl,mySmartUpload.SAVE_PHYSICAL);
}
}
catch(Exception e){e.printStackTrace();sign = false; }
if(sign==true)
{
response.getWriter().write("type='text/javascript'<script>parent.callback('3')</script>");
}else
{
response.getWriter().write("<script>parent.callback('3')</script>");
}
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
}
iframe --------------------编程问答-------------------- 现在还没有人帮主解决啊
补充:Java , Java相关