当前页面: 开发资料首页 → JSP 专题 → 网页无法提交 让我很不理解的一个问题(spring mvc)。
网页无法提交 让我很不理解的一个问题(spring mvc)。
摘要: 网页无法提交 让我很不理解的一个问题(spring mvc)。
<form name="formuser" enctype="multipart/form-data" method="POST">
<input type="file" name="files" >
<input type="submit" id="submit" value="提交表单" />
</form>
这个是我的提交页面代码
public class CallingValidator implements Validator {
public boolean supports(Class clazz) {
return CallingInfo.class.isAssignableFrom(clazz);
}
public void validate(Object obj, Errors errors) {
CallingInfo info =(CallingInfo)obj;
}
}
判断代码。
public class CallingInfoAction extends SimpleFormController {
private String UploadFile="files";
protected ModelAndView onSubmit(HttpServletRequest req,
HttpServletResponse rep, Object cmd, BindException ex) {
ModelAndView mv = null;
return mv;
}
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
System.out.println(new java.util.Date()+" -> "+CallingInfoAction.class.getName()+" -> formBackingObject");
String action = Tools.getString(request.getParameter("action"));
CallingInfo callinfo = new CallingInfo();
callinfo.setActionType(action);
if(action.equals("edit")){
String id =request.getParameter("id");
ClassPathXmlApplicationContext tx = new ClassPathXmlApplicationContext(
ConfigMessage.APPLICATIONCONTEXT);
DaoImpl dao = (DaoImpl) tx.getBean(ConfigMessage.BEAN);
Callingimg call = (Callingimg)dao.get(Callingimg.class, Integer.valueOf(id));
callinfo.setFiles(null);
tx.close();
}
return callinfo;
}
}
逻辑层代码
我的问题就出现了,我在页面上提交file 但是一直都是在本页上显示,没有CallingInfoAction -》onSubmit 里面,进入了CallingValidator ,一直在本页显示,但是去掉file上传 改成text 就可以进入CallingInfoAction -》onSubmit 进入数据保存
帮顶
帮顶
file文件是一种数据结构,不想text传的是字符串,
比如啊,struts里面有个FormFile类来专门处理这个东动,
enctype="multipart/form-data"
怀疑是这句问题
我以前的几个页面都是可以的,唯独这个页面有问题,感觉都是一些不可思议的理解。。让我很头疼。。
FormFile 变量声明了吗?
有没有出错信息?
去google上搜索一下 struts upload的参考把
to alley_zhan(晓柯)
没有任何的出错信息 以前的几个上传附件也是这样做的没有任何的问题。这次能了几天了 ,还是不能提交,不是说,不能在后面的页面得到参数,而是提交就感觉在刷新本页一样,只是输入的数据保留而已。
还有这个是spring mvc 不是struts
请大家帮忙顶 ,顶也有分的。这个问题太奇怪了。
感谢大家 帮忙顶下。。。
是不是验证没通过?你设置断点看一下啦
callinfo.setActionType(action);
是不是这里写错了?你有设置这个action吗?
action 只不过是一个String 值
找到报错了。
在上传附件的时候 他会报这个错误,
Failed to convert property value of type [org.springframework.web.multipart.commons.CommonsMultipartFile] to required type [byte[]] for property files; nested exception is java.lang.IllegalArgumentException: argument type mismatch
但是我找不到这个错误 错在那里了?
http://community.csdn.net/Expert/topic/4924/4924883.xml