对不起我的英语不好。我想将图像上传到数据库。我使用Maven,休眠模式。我遵循这个答案。很多时间我尝试解决此问题,但没有成功。我有这个错误:
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)
吼叫我的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>
这个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
}}
它是我的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>
您正在使用可以在tomcat 8.0.x和Java 7及更高版本上运行的serlvet-api 3.1,但是您正在使用Java 1.4。您必须使这些版本兼容。这是完整的列表:对于Apache Tomcat版本
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句