日期:2014-05-18  浏览次数:20733 次

(菜鸟问题 散分)关于使用FormFile文件上传的问题
如何定义一个类来将JSP中file的文件转化为FormFile

------解决方案--------------------
jsp的写法:
  
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html>
<head>
<title>上传文件</title>
</head>
<script type="text/JavaScript">
</script>
<body>
<html:form action="XXXX.do" enctype="multipart/form-data">
<table>

<tr class="bluetd">
<td align="right">上传文档:</td>
<td colspan="3" align="left">
<input type="file" name="formFile" size="45" onKeyDown="return false" ondrag="return false" onKeyPress="return false" onpaste="return false" ondragend ="return false" ondragenter ="return false" ondragleave="return false"></td>
</tr>

</table>
</html:form>
</body>
</html:html>

Form的写法:
//上传文档
private FormFile formFile;

public void setFileNameShow(String fileNameShow) {
this.fileNameShow = fileNameShow;
}
public FormFile getFormFile() {
return formFile;
}

action的写法:

public ActionForward upload(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

ResearchForm researchForm = (ResearchForm) form;
FormFile ff = ResearchForm.getFormFile();
System.out.println(ff.getFileName());
return mapping.findForward("success");
}

------解决方案--------------------
他是用的struts,而且还没把config放上来。JSP 和 ACTION 就是那些了。