使用jquery-fileupload.js实现文件上传-webx3

1、参考文章:http://blog.csdn.net/programmer_sir/article/details/29570935

2、goToUp.vm

<!DOCTYPE html>
<html>
<head>
    <title>接口消息监控</title>
    <script src="../../../js/jquery.min.js"></script>
    <script src="../../../js/jquery-file-upload/jquery-1.11.0.min.js"></script>
    <script src="../../../js/jquery-file-upload/jquery-upload.min.js"></script>
</head>
<body>
<div >
    你好:$!{name}
    <input type="hidden" id="uploadUrl" value="requireUploadFile.do" />
    <input id="file" type="file" name="file"/>
    <input type="button" value="提交" onclick="gotoU()"/>
</div>
</body>
<script>

    function gotoU() {
        $("#file").upload({
            action: $("#uploadUrl").val(),
            oncomplete: function(result) {
                var mess = result.responseText;
                // 上传成功处理.更换页面显示图片。
                if(result.status == 200){
                    alert("success");
                    $.ligerDialog.success("图片已上传成功,请完善教师其它信息.");
                }else
                {
                    alert("失败");
                    $.ligerDialog.error(mess);
                }
            },onprogress: function(e) {

            }
        });
    }
</script>
</html>


2、GoToUp.java

package com.lxp.test.demoproject.app1.module.screen;

import com.alibaba.citrus.turbine.Context;

public class GoToUp {
    public void execute(Context context) {
        context.put("name", "你好");
    }
}
3、RequireUploadFile.java    就在screen下

package com.lxp.test.demoproject.app1.module.screen;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.TurbineRunData;
import com.alibaba.citrus.turbine.dataresolver.Param;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

public class RequireUploadFile {
    public void execute(Context context,TurbineRunData runData) {
        FileItem file = runData.getParameters().getFileItem("file");
        String fileName = "D:/"+file.getName();
        System.out.print("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:"+fileName);
        try {

            File uploadFile = new File(fileName);
            FileCopyUtils.copy(file.get(), uploadFile);
            PrintWriter writer = runData.getResponse().getWriter();
            writer.write("success:true");
        } catch (Exception e) {
           e.getMessage();
        }
    }
}







你可能感兴趣的:(使用jquery-fileupload.js实现文件上传-webx3)