spring mvcコードを使用すると、このエラーが発生し続けます。spring mvcを使用して画像をアップロードしようとしていますが、欠落している引数は何ですか。
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is java.lang.IllegalArgumentException: argument type mismatch
java.lang.IllegalArgumentException: argument type mismatch
...
私のディスパッチャーサーブレットは
<context:component-scan base-package="com.ImageUploadSpring.Controller" />
<!-- <bean id="simpleHandler" class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/> -->
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/Upload.html">FileUpload</prop>
</props>
</property>
</bean>
<bean id="FileUpload" class="com.ImageUploadSpring.Controller.FileUpload">
<property name="commandName" value="ImageUpload"/>
<property name="commandClass" value="com.ImageUploadSpring.Bean.UploadItem"/>
<property name="formView" value="ImageUpload"/>
<property name="successView" value="message"/>
</bean>
<bean id="FileUpload" class="com.ImageUploadSpring.Controller.FileUpload"></bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/" />
<property name="suffix" value=".html" />
</bean>
コントローラークラスは
public class FileUpload extends SimpleFormController{
@RequestMapping(value = "/Upload.html", method = RequestMethod.POST)
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors,HttpSession session) {
System.out.println("inside submit method");
try{
UploadItem item=(UploadItem)command;
MultipartFile file = item.getFile();
InputStream inputStream = null;
OutputStream outputStream = null;
if (file.getSize() > 0) {
inputStream = file.getInputStream();
outputStream = new FileOutputStream("D:/UploadedFiles/Images/"
+ file.getOriginalFilename());
System.out.println(file.getOriginalFilename());
int readBytes = 0;
byte[] buffer = new byte[8192];
while ((readBytes = inputStream.read(buffer, 0, 8192)) != -1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
session.setAttribute("uploadFile", "D:/UploadedFiles/Images/"
+ file.getOriginalFilename());
}
}catch (Exception e) {
e.printStackTrace();
}
return new ModelAndView("message");
}
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder)
throws ServletException {
binder.registerCustomEditor(byte[].class, new ByteArrayMultipartFileEditor());
}
そして私のhtmlページは
<form name="ImageUpload" action="/ImageUploadSpring/service/Upload.html" method="POST" enctype="multipart/form-data">
<div>
Select images:
<input type="text" id="box"/>
<input type="file" id="UploadFile" name="UploadFile" onchange="CopyMe(this,'box');" accept="image/*" size="40" style="width: 91px;" multiple />
<br><br>
<input type="submit" value="Upload" /><br><br>
</div>
</form>