0

我正在尝试使用 spring 的 _metgod 隐藏属性处理伪装的 PUT,但即使使用了 HiddenHttpMethodFilter,请求也会以 POST 的形式通过。你还需要做什么才能在 glassfish 中启用吗?Web.xml 如下:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Jester</display-name>


<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/jester-persistence.xml
        /WEB-INF/jester-service.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<servlet>
    <servlet-name>jester</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jester</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>


<filter>
    <filter-name>filter1</filter-name>
    <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>filter1</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

</web-app>
4

1 回答 1

1

好的,我发现这是因为我阅读了很多关于 enctype="multipart/form-data" 的问题。结果证明 sf:form 标签解析为多部分表单,因此 spring 尝试使用 MultipartResolver 处理它们。解决此问题的 XML 如下:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <display-name>Jester</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/jester-persistence.xml
            /WEB-INF/jester-service.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <servlet>
        <servlet-name>jester</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <!-- Needed for processing multipart forms ahead of the HiddenHttpMethodFilter -->
        <multipart-config>
            <location>/tmp</location>
            <max-file-size>20848820</max-file-size>
            <max-request-size>418018841</max-request-size>
            <file-size-threshold>1048576</file-size-threshold>
        </multipart-config>
    </servlet>

    <servlet-mapping>
        <servlet-name>jester</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- Needed for processing multipart forms ahead of the HiddenHttpMethodFilter -->
    <filter>
        <filter-name>multipartFilter</filter-name>
        <filter-class>org.springframework.web.multipart.support.MultipartFilter</filter-class>
        <init-param>
            <param-name>multipartResolverBeanName</param-name>
            <param-value>filterMultipartResolver</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>multipartFilter</filter-name>
        <servlet-name>jester</servlet-name>
    </filter-mapping>

    <!-- Convert Masqueraded PUT and DELETE requests -->
    <filter>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>hiddenHttpMethodFilter</filter-name>
        <servlet-name>jester</servlet-name>
    </filter-mapping>

</web-app>
于 2012-10-10T23:04:47.820 回答