首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Struts1.3下传文件

2012-10-27 
Struts1.3上传文件Struts1.3上传图片uploadFile.jsp:%@ page languagejava pageEncodingISO-8859-1

Struts1.3上传文件
Struts1.3上传图片
uploadFile.jsp:
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html>
<head>
  <title>JSP for UploadFileForm form</title>
</head>
<body>
  <html:form action="/uploadFile">
   file : <html:file property="file"/><html:errors property="file"/><br/>
   <html:submit/><html:cancel/>
  </html:form>
</body>
</html>


public ActionForward uploadfile(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {

UploadActionForm uaf = (UploadActionForm)form;
  String fileName = null;
  FormFile formFile = uaf.getMyFile();
  if (!"".equals(uaf.getMyFileName())){
   String fileExt = formFile.getFileName().substring(formFile.getFileName().indexOf("."));
   fileName = uaf.getMyFileName()+fileExt;}
  else fileName = formFile.getFileName();
  FileOutputStream fos = new FileOutputStream("d:\"+fileName);
  fos.write(formFile.getFileData());
}

热点排行