1

Sorry for my English. I want upload image to database.I use maven, hibernate. I follow this answer. Many time i tried fix this, but without success. I have this error:

SEVERE: Servlet.service() for servlet [addpost] in context with path [/landingpage] threw exception [Servlet execution threw an exception] with root cause
java.lang.NoSuchMethodError: javax.servlet.http.Part.getSubmittedFileName()Ljava/lang/String;
    at app.web.landingpage.serv.addpost.doPost(addpost.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

Bellow my jsp

<form method="POST" action="addpost" enctype="multipart/form-data">
<input type="file" class="btn btn-default" name="file" />
                    <p><button type="submit">add post</button></p>
</form>

And this addpost servlet:

@MultipartConfig
public class addpost extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //code 
    Part filePart = request.getPart("file"); // Retrieves <input type="file" name="file">
        String fileName = filePart.getSubmittedFileName();//its line 43
    //code
    }}

its my xml

<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>app.web</groupId>
  <artifactId>landingpage</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>landingpage</name>
  <url>http://maven.apache.org</url>

  <dependencies>


    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
    </dependency>


    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.1</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.2.1.Final</version>
    </dependency>

    <dependency>
        <groupId>jstl</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>


    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <version>1.1.2</version>
    </dependency>

    <dependency>
      <groupId>com.sun.jersey</groupId>
      <artifactId>jersey-servlet</artifactId>
      <version>1.13</version>
    </dependency>



  </dependencies> 

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
          <source>1.4</source>
          <target>1.4</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
Community
  • 1
  • 1
asdascascaedfa
  • 137
  • 4
  • 11

1 Answers1

4

You are using serlvet-api 3.1 that can be run on tomcat 8.0.x and Java 7 and later but you are using Java 1.4. You have to make these versions compatible. Here is the complete list: for Apache Tomcat Versions

Nikola
  • 320
  • 2
  • 5