在jersey上传文件时找不到404资源

时间:2018-04-02 06:52:13

标签: java jersey pom.xml

我正在开发上传文件的泽西网络服务。我已经为此编写了代码,但每当我点击var getData = function() { return new Promise((resolve, reject) => { setTimeout(() => { resolve(42); }, 500); }) } var getDataMoreData = function() { return new Promise((resolve, reject) => { setTimeout(() => { resolve(43); }, 300); }) } getData() .then((data) => console.log('Data', data)) .then(getDataMoreData) .then((data) => console.log('data--', data));的提交按钮上传文件时,就会抛出错误404资源找不到。

我不知道这段代码中我错在哪里请帮我改进一下。

提前致谢。

的web.xml:

WelcomeFile.jsp

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>Rest</display-name>

    <welcome-file-list>
            <welcome-file>/WEB-INF/ViewPages/WelcomeFile.jsp</welcome-file>
    </welcome-file-list>

</web-app>

WelcomeFile.jsp:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Rest</groupId>
    <artifactId>Rest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <repositories>
        <repository>
            <id>maven2-repository.java.net</id>
            <name>Java.net Repository for Maven</name>
            <url>http://download.java.net/maven/2/</url>
            <layout>default</layout>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.8</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey.contribs</groupId>
            <artifactId>jersey-multipart</artifactId>
            <version>1.8</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <webXml>WebContent\WEB-INF\web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

UploadFileService.java

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Welcome File</title>
</head>
<body>
    <h1>File Upload with Jersey</h1>

    <form action="file/upload" method="post" enctype="multipart/form-data">

       <p>
        Select a file : <input type="file" name="file" size="45" />
       </p>

       <input type="submit" value="Upload It" />
    </form>

</body>
</html>

0 个答案:

没有答案