【问题标题】:404 error when referencing fileUpload interceptor in Struts 2在 Struts 2 中引用 fileUpload 拦截器时出现 404 错误
【发布时间】:2013-12-03 00:21:08
【问题描述】:

我正在使用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>
   <constant name="struts.devMode" value="true" />
   <constant name="struts.multipart.maxSize" value="1000000" />
   
   <package name="helloworld" extends="struts-default">
      
      <interceptors>
         <interceptor name="myinterceptor"
            class="com.struts2examples.MyInterceptor" />
         <interceptor name="myinterceptor1"
            class="com.struts2examples.MyInterceptor1" />
         
      </interceptors>
      
      <action name="hello" 
            class="com.struts2examples.HelloWorldAction" 
            method="execute">
            <result name="success">/HelloWorld.jsp</result>
            <result name="error">/AccessDenied.jsp</result>
            <interceptor-ref name="params"/>
            <interceptor-ref name="myinterceptor"/>
            <interceptor-ref name="myinterceptor1"/>
      </action>
      
      <action name="hello1" 
            class="com.struts2examples.HelloWorldAction1" 
            method="execute">
            <result name="success" type="freemarker">
                <param name="location">/hello.fm</param>
            </result>
            <result name="nopassnofail" type="redirect">
                <param name="location">/NewWorld.jsp</param >
            </result>
            <result name="error">/AccessDenied.jsp</result>
      </action>
      
      <action name="upload" class="com.struts2examples.UploadFile" method="execute">
      
       <interceptor-ref name="fileUpload">
           <param name="allowedTypes">image/jpeg,image/gif</param>
       </interceptor-ref>
       <result name="success">/success.jsp</result>
       <result name="error">/error.jsp</result>
      </action>
   </package>
</struts>

在我添加最后一个操作 upload 之前它正在工作。当我启动服务器时,它向我显示 404 错误。有人可以帮我解决这个问题。我觉得问题是由于&lt;interceptor-ref name="fileUpload"&gt;.

【问题讨论】:

    标签: java file-upload struts2 http-status-code-404


    【解决方案1】:

    尝试在&lt;interceptor-ref name="fileUpload"&gt;之后添加&lt;interceptor-ref name="defaultStack"&gt;。如果您在操作中添加显式拦截器,defaultStack 就会消失。

    【讨论】:

    • 不,它没有解决问题。我在服务器上收到 404。
    【解决方案2】:

    试着这样写再试

    <interceptor-ref name="defaultStack"/>
    <interceptor-ref name="fileUpload">
       <param name="allowedTypes">image/jpeg,image/gif</param>
    </interceptor-ref>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2014-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多