Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 请求的资源在struts2文件上载中不可用_Java_Jsp_Struts2 - Fatal编程技术网

Java 请求的资源在struts2文件上载中不可用

Java 请求的资源在struts2文件上载中不可用,java,jsp,struts2,Java,Jsp,Struts2,我是Struts2新手,正在开发一个带有文件上传选项的web应用程序。所有内容都已配置,但当我运行模块HTTP Status 404时出现错误:请求的资源不可用。(链接:http://localhost:8080/File_Upload/index.jsp)。请在下面找到我的配置, index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%

我是Struts2新手,正在开发一个带有文件上传选项的web应用程序。所有内容都已配置,但当我运行模块HTTP Status 404时出现错误:请求的资源不可用。(链接:
http://localhost:8080/File_Upload/index.jsp
)。请在下面找到我的配置, index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
<title>File Upload</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.11.3.js"></script>  
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/ajaxfileupload.js"></script>  
        <script type="text/javascript">  
    function ajaxFileUpload()  
    {  

        $("#loading")  
        .ajaxStart(function(){  
            $(this).show();  
        })//  
        .ajaxComplete(function(){  
            $(this).hide();  
        });//  

        $.ajaxFileUpload  
        (  
            {  
                url:'fileUploadAction.action',//  
                secureuri:false,//false  
                fileElementId:'myFile',//id  <input type="file" id="file" name="file" />  
                dataType: 'json',// json  
                success: function (data, status)  //  
                {  
                    //alert(data.message);//jsonmessage,messagestruts2  
                    $("#file_name").attr("value",data.myFile);
                    $("#file_path").attr("value",data.myFileFileName);
                    if(typeof(data.error) != 'undefined')  
                    {  
                        if(data.error != '')  
                        {  
                            alert(data.error);  
                        }else  
                        {  
                            alert(data.myFile);  
                        }  
                    }  
                },  
                error: function (data, status, e)//  
                {  
                    alert(e);  
                }  
            }  
        )  

        return false;  

    }  
    </script>  
</head>
<body>
   <form action="upload" method="post" enctype="multipart/form-data">
      <label for="myFile">Upload your file</label>
      <input type="file" name="myFile" id="myFile"/>
      <input type="button" value="" onclick="return ajaxFileUpload();">
      <input type="hidden" name="file_name[]" id="file_name[]" value=""/>
      <input type="hidden" name="file_path[]" id="file_path[]" value=""/> 
      <input type="submit"/>
   </form>
   <div id="loading"><span style="position: fixed;left: 50%;top: 50%; transform: translate(-50%, -50%); color:#f3cbbb ">
   <img src="<%=request.getContextPath()%>/images/ajax-loader.gif" alt="loading" width="200" height="200" style="padding-left:85px">
   <br /><br />
   <span style=" font-weight: 700; font-size: 18px">Please wait,File is being uploaded
   </span></span>
   </div>

</body>
</html>

文件上传
函数ajaxFileUpload()
{  
$(“#加载”)
.ajaxStart(函数(){
$(this.show();
})//  
.ajaxComplete(函数(){
$(this.hide();
});//  
$.ajaxFileUpload
(  
{  
url:'fileUploadAction.action',//
secureuri:false,//false
fileElementId:'myFile',//id
数据类型:'json',//json
成功:功能(数据、状态)//
{  
//警报(data.message);//jsonmessage,messagestruts2
$(“#文件名”).attr(“值”,data.myFile);
$(“#file_path”).attr(“value”,data.myFileFileName);
if(typeof(data.error)!=“未定义”)
{  
如果(data.error!='')
{  
警报(数据错误);
}否则
{  
警报(data.myFile);
}  
}  
},  
错误:功能(数据、状态、e)//
{  
警报(e);
}  
}  
)  
返回false;
}  
上传你的文件
/images/ajax loader.gif“alt=“load”width=“200”height=“200”style=“padding left:85px”>


请稍候,正在上载文件
struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
   <package name="default" extends="struts-default">
    <action name="fileUploadAction" class="com.tutorialspoint.struts2.MultipleFileUploadAction">  
              <result type="json" name="success">  
                <param name="contentType">text/html</param>  
            </result>  
            <result type="json" name="error">  
                <param name="contentType">text/html</param>  
            </result> 
        </action> 
   </package>
</struts>


您必须在struts.xml文件包中添加此操作

<action name="index">
    <result>/index.jsp</result>
</action>

它将返回
index.jsp
您必须在struts.xml中添加的
index.jsp

此操作将添加到您的默认包中

<action name="index">
    <result>/index.jsp</result>
</action>

它将返回
index.jsp

此代码的哪部分不起作用?查看index page.index.jsp文件的一部分。请检查我的配置是否正确。您没有索引页面的操作。此代码的哪部分不起作用?查看index page.index.jsp文件的一部分。请检查我的配置是否正确r不是。您没有索引页的操作。
<action name="index">
    <result>/index.jsp</result>
</action>