2017-07-11 6 views
0
unterstützt

in meinem HTML schrieb ichSpring MVC - request "Post" nicht

<form method="POST" enctype="multipart/form-data" action="http://localhost:8080/uploadXML"> 

    <input type="file" id="importFile" /> <br> 
    <button type="submit" class="buttonUpload" >Upload</button> 
</form> 

My-Controller wie folgt aussieht:

@RestController 
public class Controller { 



@RequestMapping(value="/uploadXML", method=RequestMethod.POST) 
public @ResponseBody String handleFileUpload( 
     @RequestParam("file") MultipartFile file){ 
     String name = "test11"; 
    if (!file.isEmpty()) { 
     try { 
      byte[] bytes = file.getBytes(); 
      BufferedOutputStream stream = 
        new BufferedOutputStream(new FileOutputStream(new File(name + "-uploaded"))); 
      stream.write(bytes); 
      stream.close(); 
      return "You successfully uploaded " + name + " into " + name + "-uploaded !"; 
     } catch (Exception e) { 
      return "You failed to upload " + name + " => " + e.getMessage(); 
     } 
    } else { 
     return "You failed to upload " + name + " because the file was empty."; 
    } 
} 

Ich bekomme immer den Fehlercode 405, wenn Sie den Absenden-Button drücken: "Es ist ein unerwarteter Fehler aufgetreten (Typ = Methode nicht zulässig, Status = 405). Anforderungsmethode 'POST' nicht unterstützt". This is what my package explorer looks like

mein pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 

http://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0

<groupId>springboot-angularjs</groupId> 
<artifactId>springboot-angularjs</artifactId> 
<version>1.0-SNAPSHOT</version> 

<parent> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-parent</artifactId> 
    <version>1.3.3.RELEASE</version> 
</parent> 
<dependencies> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>angularjs</artifactId> 
     <version>1.4.9</version> 
     <scope>runtime</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.webjars</groupId> 
     <artifactId>bootstrap</artifactId> 
     <version>3.3.6</version> 
     <scope>runtime</scope> 
    </dependency> 

    <dependency> 
<groupId>javax.xml.bind</groupId> 
<artifactId>jaxb-api</artifactId> 
<version>2.2.5</version> 
<exclusions> 
<exclusion> 
       <groupId>org.bouncycastle</groupId> 
       <artifactId>bcmail-jdk14</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>bouncycastle</groupId> 
       <artifactId>bcmail-jdk14</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.bouncycastle</groupId> 
       <artifactId>bctsp-jdk14</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>bouncycastle</groupId> 
       <artifactId>bcprov-jdk14</artifactId> 
</exclusion> 
</exclusions> 
</dependency> 
<dependency> 
<groupId>com.sun.xml.bind</groupId> 
<artifactId>jaxb-impl</artifactId> 
<version>2.2.5</version> 
<exclusions> 
<exclusion> 
      <groupId>org.bouncycastle</groupId> 
       <artifactId>bcmail-jdk14</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>bouncycastle</groupId> 
       <artifactId>bcmail-jdk14</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>org.bouncycastle</groupId> 
       <artifactId>bctsp-jdk14</artifactId> 
      </exclusion> 
      <exclusion> 
       <groupId>bouncycastle</groupId> 
       <artifactId>bcprov-jdk14</artifactId> 
    </exclusion> 
    </exclusions> 
    </dependency> 


    </dependencies> 
    </project> 

Kann jemand meinen Fehler sehen und kann mir erklären, wie die Dateiübertragung funktionieren kann? Vielen Dank!

+0

Bitte hinzufügen Ausnahme StackTrace. –

+0

"http: // localhost: 8080/uploadXMLFailed zum Laden der Ressource: Der Server hat mit dem Status 405 (Method Not Allowed) geantwortet" –

+0

Fügen Sie Server-Side-Logs hinzu und fügen Sie auch Ihre Spring-Konfiguration hinzu. –

Antwort

Verwandte Themen