0

我正在尝试将uploadify与struts2一起使用,当我选择一个文件时,它显示,http错误302。请有人指出我的问题。我认为它根本没有到达服务器,因为一开始就没有打印语句的输出。

jsp

<!DOCTYPE html>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sj" uri="/struts-jquery-tags"%>
<html lang="en">
    <head>
        <% 
            String sessionid = request.getSession().getId().toString();
            String path= request.getContextPath();
         %>
        <sj:head jqueryui="true" compressed="false"/>
        <title>Uploadify test</title>
        <script src="uploadify/jquery.uploadify.min.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="uploadify/uploadify.css">
        <script type="text/javascript" id="015e9c19-de54-402c-8ce4-93a29d054dbc"><!--/*--><![CDATA[/*><!--*/
        $(document).ready(function(){
            var id='<%=sessionid%>';
            var path='<%=path%>';
            alert(id);
                $('#file_upload1').uploadify({
                        uploader:'uploads?jsessionid='+id, 
                        scriptAccess:'always', 
                        auto:true, 
                        multi:true, 
                        swf:'uploadify/uploadify.swf', 
                        cancelImg:'uploadify/uploadify-cancel.png',
                        onError : function(event, queueID, fileObj, errorObj) { alert(errorObj.type + ' ' + errorObj.info ); }
                });
        });
        /*-->]]>*/
    </script>

    </head>
    <body>
       <input name="file_upload" type="file" id="file_upload1"/>
       <a href="javascript:$('#file_upload1').uploadifyUpload();">Upload Files</a>
    </body>
</html>

行动

@Namespace("/")
public class UploadifyAction extends ActionSupport{

    private List<File> fileUpload = new ArrayList<File>();
    private List<String> fileUploadContentType = new ArrayList<String>();
    private List<String> fileUploadFileName = new ArrayList<String>();

    public List<File> getFileUpload() {
        return fileUpload;
    }

    public void setFileUpload(List<File> fileUpload) {
        this.fileUpload = fileUpload;
    }

    public List<String> getFileUploadContentType() {
        return fileUploadContentType;
    }

    public void setFileUploadContentType(List<String> fileUploadContentType) {
        this.fileUploadContentType = fileUploadContentType;
    }

    public List<String> getFileUploadFileName() {
        return fileUploadFileName;
    }

    public void setFileUploadFileName(List<String> fileUploadFileName) {
        this.fileUploadFileName = fileUploadFileName;
    }
 @Action(value="uploads")
    public void upload() throws Exception{
            System.out.println("in");
        for (File file: fileUpload) {
            System.out.println("File :" + file);
        }

        for (String fileName: fileUploadFileName) {
            System.out.println("Filename : " + fileName);
        }

        for (String fileContentType: fileUploadContentType) {
            System.out.println("File type : " + fileContentType);
        }

    }

  @Action(value="fileUpload", results = { @Result(name="none",location="/uploadify.jsp")
    })
    public String display() {
        return NONE;
    }
}

我尝试更改其给出 404 的 url,但使用当前 url 即上传器我收到 http 302 错误

谢谢并恭祝安康。

4

0 回答 0