【发布时间】:2020-03-31 12:29:26
【问题描述】:
I've already looked at this one 和相关的票都没有用。
我有,看起来可能是最简单的例子
<h:form enctype="multipart/form-data" prependId="false">
<h:outputText value="File: "></h:outputText>
<h:inputFile value="#{configUploadController.uploadedFile}" />
<h:commandButton value="Save" type="submit" action="#{configUploadController.uploadFile}" style="color: red;"></h:commandButton>
</h:form>
我在我的uploadFile 方法中设置了一个断点,但它从来没有被击中。当我从它尝试提交的表单中删除 enctype 时,我得到了明显的错误......
javax.servlet.ServletException: Content-Type != multipart/form-data
为了完整起见,我删除了<h:inputFile> 和enctype,可以看到我的断点被命中。当我将 enctype 设置为 text/plain 时,它 DOESNT 到达断点。但是,当我将 enctype 设置为乱码时,它 确实 会遇到断点 :(
我是否在某处缺少依赖项或配置?
如果重要的话,我的 web.xml...
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- File(s) appended to a request for a URL that is not mapped to a web
component -->
<welcome-file-list>
<welcome-file>status.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<listener>
<description>Initializes Oracle JSF</description>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Define the JSF servlet (manages the request processing life cycle for
JavaServer Faces) -->
<servlet>
<servlet-name>faces-servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<!-- Map following files to the JSF servlet -->
<servlet-mapping>
<servlet-name>faces-servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
- jsf-api-2.2.15
- jsf-impl-2.2.15
- el-api-2.2
- el-impl-2.2
- 码头 9.4.18
- javax.servlet-api-3.1.0
【问题讨论】:
-
如果您查看浏览器的检查/网络面板,该失败请求的
Content-Type请求标头是什么? -
关于这个主题的答案比你链接的那个稍新 - stackoverflow.com/questions/28715559/…
-
当我设置 enctype="gibberish" 请求 Content-Type 是 application/x-www-form-urlencoded
-
lol @JoakimErdfelt 只更新了 2 个月,我没有使用 jsf 2.1 或 primefaces