我正在尝试使用maven在Spring MVC中进行文件上传的简单示例,然后我将阅读本教程.
但是我收到了这个错误
java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory
Run Code Online (Sandbox Code Playgroud)
我还在pom.xml中包含了依赖项
<!-- Apache Commons Upload -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
也在dispatcher-servlet.xml中
<!-- Configure the multipart resolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="100000"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
所以,你能帮我解决我的错误吗?
提前致谢.
我对这一小段代码有疑问
SimpleDateFormat sf = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
String str = "2010-03-13 01:01:22";
Date date = sf.parse(str);
SimpleDateFormat f = new SimpleDateFormat("d MMM yyyy hh:mm aaa");
System.out.println(" Date " + f.format(date));
Run Code Online (Sandbox Code Playgroud)
输出:
Date 13 Jan 2010 01:01 AM
Run Code Online (Sandbox Code Playgroud)
代码似乎很好,但我仍然得到月份名称错误.请帮忙 !!谢谢.
我有一个简单的表单,可以选择上传图片,但上传文件,我没有使用此方法
<form:input path="logoData" id="image" type="file" />
Run Code Online (Sandbox Code Playgroud)
相反,我使用的是ajax upload jquery pulgin.问题是upload.parseRequest(request)在下面的代码中返回null:
@RequestMapping(value = "/upload.htm", method = RequestMethod.POST)
public @ResponseBody String upload(HttpServletRequest request) throws FileUploadException{
// Create a factory for disk-based file items
FileItemFactory factory = new DiskFileItemFactory();
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List<FileItem> items = upload.parseRequest(request);
System.out.println("====ITEMS====" + items.size());
System.out.println("----REQUEST---" +request.getParameter("uploadImg"));
System.out.println("-----SIZE----" +request.getParameterMap().size());
Map<String, String> map = request.getParameterMap();
for(Map.Entry<String, String> entry : map.entrySet()){
System.out.println("----KEY---" + entry.getKey() + "----value---" …Run Code Online (Sandbox Code Playgroud)