如何解决spring中的多部分解析器??java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory
pom.xml 因此,当我给出一张图片并点击submit时,我会遇到这样的错误 甚至我在pom.xml中添加了“commons logging” momcab-servlet.xml中的“multipartResolver”的“bean”甚至没有在我的tomcat中运行。所以我知道我的错误发生在哪里。在此方面的任何帮助都是感激的。如何解决spring中的多部分解析器??java.lang.NoClassDefFoundError:org/apache/commons/fileupload/FileItemFactory,java,xml,spring,maven,multipartform-data,Java,Xml,Spring,Maven,Multipartform Data,pom.xml 因此,当我给出一张图片并点击submit时,我会遇到这样的错误 甚至我在pom.xml中添加了“commons logging” momcab-servlet.xml中的“multipartResolver”的“bean”甚至没有在我的tomcat中运行。所以我知道我的错误发生在哪里。在此方面的任何帮助都是感激的。 谢谢你,我解决了我的问题。我刚刚添加了commons fileupload,但我没有添加commons io,所以我添加了它们,我的问题就解决了 package co
谢谢你,我解决了我的问题。我刚刚添加了
commons fileupload
,但我没有添加commons io
,所以我添加了它们,我的问题就解决了
package com.ssts.momcab.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.ssts.momcab.model.Admin;
import com.ssts.momcab.model.Driver;
import com.ssts.momcab.service.BookingService;
import com.ssts.momcab.service.DriverService;
import com.ssts.momcab.util.MomcabUtil;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
public class DriverController {
@Value("${login_session_token_timeout_mnts}")
private String loginSessionTokenTimeoutMnts;
private DriverService driverService;
@Autowired(required = true)
@Qualifier(value = "driverService")
public void setDriverService(DriverService ds) {
this.driverService = ds;
}
@RequestMapping(value = "/Drivers", method = RequestMethod.GET)
public String Drivers(Model model,HttpServletRequest req,HttpServletResponse res) {
HttpSession session =req.getSession();
if(session.getAttribute("emailId")==null)
{
return "redirect:/login";
}
model.addAttribute("driver", new Driver());
return "driver";
}
@RequestMapping(value = "/Drivers/add", method = RequestMethod.POST)
public String Driver(@ModelAttribute("driver") Driver driver,@RequestParam("blobImg") MultipartFile blobImg) throws IOException {
if (driver.getId() == 0) {
// new user, add to DB
if (blobImg != null && !blobImg.isEmpty())
{
byte[] bytes = blobImg.getBytes();
driver.setBlobImg(bytes);
}
}
this.driverService.addDriver(driver);
return "redirect:/Drivers";
}
}
文件上传
文件上传
1.3.1
公地io
公地io
2.4
我解决了我的问题。我刚刚添加了commons fileupload
,但我没有添加commons io
,所以我添加了它们,我的问题就解决了
package com.ssts.momcab.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.ssts.momcab.model.Admin;
import com.ssts.momcab.model.Driver;
import com.ssts.momcab.service.BookingService;
import com.ssts.momcab.service.DriverService;
import com.ssts.momcab.util.MomcabUtil;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
public class DriverController {
@Value("${login_session_token_timeout_mnts}")
private String loginSessionTokenTimeoutMnts;
private DriverService driverService;
@Autowired(required = true)
@Qualifier(value = "driverService")
public void setDriverService(DriverService ds) {
this.driverService = ds;
}
@RequestMapping(value = "/Drivers", method = RequestMethod.GET)
public String Drivers(Model model,HttpServletRequest req,HttpServletResponse res) {
HttpSession session =req.getSession();
if(session.getAttribute("emailId")==null)
{
return "redirect:/login";
}
model.addAttribute("driver", new Driver());
return "driver";
}
@RequestMapping(value = "/Drivers/add", method = RequestMethod.POST)
public String Driver(@ModelAttribute("driver") Driver driver,@RequestParam("blobImg") MultipartFile blobImg) throws IOException {
if (driver.getId() == 0) {
// new user, add to DB
if (blobImg != null && !blobImg.isEmpty())
{
byte[] bytes = blobImg.getBytes();
driver.setBlobImg(bytes);
}
}
this.driverService.addDriver(driver);
return "redirect:/Drivers";
}
}
文件上传
文件上传
1.3.1
公地io
公地io
2.4
为什么要添加公共日志
帮助?您缺少了commons fileupload
dependency.@M.Deinum如果您滚动我发布的“pom.xml”文件,您可以看到我添加了一个依赖项“commons-logging-1.2.1”。这里的问题是,当我在pom.xml中添加“commons logging”依赖项并运行服务器时,我没有收到任何错误。但是,当我在dispatcher-servlet.xml中添加“bean”并运行服务器时,我得到的错误是您的堆栈跟踪正在抱怨commons fileupload
中缺少类,而不是commons logging
。另外,不是将堆栈跟踪作为图像发布,而是将它们作为代码发布,以便它们可读和可滚动(堆栈跟踪的有趣部分实际上丢失了)。您有一个1.2.2版的commons fileupload
依赖项,该依赖项很古老(2010年),请至少使用较新的1.3.2版本。stacktrace应该是文本,而不是图片。我们相信您有一个例外,因此最好使用文本而不是图片。为什么添加公共日志记录
会有帮助?您缺少了commons fileupload
dependency.@M.Deinum如果您滚动我发布的“pom.xml”文件,您可以看到我添加了一个依赖项“commons-logging-1.2.1”。这里的问题是,当我在pom.xml中添加“commons logging”依赖项并运行服务器时,我没有收到任何错误。但是,当我在dispatcher-servlet.xml中添加“bean”并运行服务器时,我得到的错误是您的堆栈跟踪正在抱怨commons fileupload
中缺少类,而不是commons logging
。另外,不是将堆栈跟踪作为图像发布,而是将它们作为代码发布,以便它们可读和可滚动(堆栈跟踪的有趣部分实际上丢失了)。您有一个1.2.2版的commons fileupload
依赖项,该依赖项很古老(2010年),请至少使用较新的1.3.2版本。stacktrace应该是文本,而不是图片。我们相信你有一个例外,所以最好是文字而不是图片。
<c:url var="addAction" value="/Drivers/add"></c:url>
<form:form action="${addAction}" enctype="multipart/form-data" commandName="driver">
<table width="400px" height="150px">
<tr>
<td><form:label path="name">
<spring:message text="Driver Name" />
</form:label></td>
<td><form:input path="name" /></td>
</tr>
<tr>
<td><form:label path="license">
<spring:message text="License Number" />
</form:label></td>
<td><form:input path="license" /></td>
</tr>
<tr>
<td><form:label path="password">
<spring:message text="Password" />
</form:label></td>
<td><form:input type="password" path="password" /></td>
</tr>
<tr>
<td><form:label path="address">
<spring:message text="Address" />
</form:label></td>
<td><form:input path="address" /></td>
</tr>
<tr>
<td><form:label path="number">
<spring:message text="Mobile Number" />
</form:label></td>
<td><form:input path="number" /></td>
</tr>
<tr>
<td><form:label path="blobImg">
<spring:message text="File" />
</form:label></td>
<td><form:input type="file" path="blobImg" /></td>
</tr>
<tr>
<td><input type="submit" value="<spring:message text="Submit"/>" /></td>
</tr>
</table>
</form:form>
package com.ssts.momcab.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
import com.ssts.momcab.model.Admin;
import com.ssts.momcab.model.Driver;
import com.ssts.momcab.service.BookingService;
import com.ssts.momcab.service.DriverService;
import com.ssts.momcab.util.MomcabUtil;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
@Controller
public class DriverController {
@Value("${login_session_token_timeout_mnts}")
private String loginSessionTokenTimeoutMnts;
private DriverService driverService;
@Autowired(required = true)
@Qualifier(value = "driverService")
public void setDriverService(DriverService ds) {
this.driverService = ds;
}
@RequestMapping(value = "/Drivers", method = RequestMethod.GET)
public String Drivers(Model model,HttpServletRequest req,HttpServletResponse res) {
HttpSession session =req.getSession();
if(session.getAttribute("emailId")==null)
{
return "redirect:/login";
}
model.addAttribute("driver", new Driver());
return "driver";
}
@RequestMapping(value = "/Drivers/add", method = RequestMethod.POST)
public String Driver(@ModelAttribute("driver") Driver driver,@RequestParam("blobImg") MultipartFile blobImg) throws IOException {
if (driver.getId() == 0) {
// new user, add to DB
if (blobImg != null && !blobImg.isEmpty())
{
byte[] bytes = blobImg.getBytes();
driver.setBlobImg(bytes);
}
}
this.driverService.addDriver(driver);
return "redirect:/Drivers";
}
}
<!-- Apache Commons FileUpload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>