我正在尝试将Multipart Form作为POST请求发送到Jersey 2.22.1服务器。此请求包含文件和多个文本字段。服务器端发生的事情是我只能接收文件作为InputStream,但我接收的所有文本参数都是null。
以下是我所拥有的:
的pom.xml:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.22.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.22.1</version> <!-- Make sure the Jersey matches
the one you are currently using -->
</dependency>
<dependency>
<groupId>org.jvnet.mimepull</groupId>
<artifactId>mimepull</artifactId>
<version>1.9.6</version>
</dependency>
的web.xml:
<servlet>
<servlet-name>vedica-api</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
org.glassfish.jersey.media.multipart.MultiPartFeature
</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.nws.vedica.api,com.fasterxml.jackson</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
和代码:
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
...
@POST
@Produces("text/plain")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createDocument(
@FormDataParam("meno") String name,
@FormDataParam("rc") String rc,
@FormDataParam("typzml") String typzml,
@FormDataParam("auto") String auto,
@FormDataParam("verzia") String verzia,
@FormDataParam("documentcustomname") String doccustomname,
@FormDataParam("docpath") String docpath,
@FormDataParam("file") InputStream data,
@FormDataParam("file") FormDataContentDisposition fileInfo
) {
...
return Response.ok().build();
}
所以所有String参数都为空。
以下是我发送请求的截图:
你能解释一下我做错了什么以及如何解决这个问题?
由于
答案 0 :(得分:0)