Struts 1.2 批量上传。
来源:互联网 发布:大尺度美剧 知乎 编辑:程序博客网 时间:2024/06/05 09:24
网上找的代码不知道为啥都不能用,自己写一个简陋点的。
struts-config.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config> <data-sources /> <form-beans > <form-bean name="ttForm" type="action.TtForm" /></form-beans> <global-exceptions /> <global-forwards /> <action-mappings > <action path="/tt" scope="request" name="ttForm" type="action.TtAction" /> </action-mappings> <message-resources parameter="ApplicationResources" /> </struts-config>
ActionForm:
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */package action;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.upload.FormFile;import org.apache.struts.validator.LazyValidatorForm;/** * MyEclipse Struts * Creation date: 06-21-2008 * * XDoclet definition: * @struts.form name="ttForm" */public class TtForm extends ActionForm {/* * Generated Methods */private Map<String, FormFile> map = new HashMap<String, FormFile>();/** * Method validate * @param mapping * @param request * @return ActionErrors */public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {// TODO Auto-generated method stubreturn null;}public void setFile(String key,FormFile f) {if (f != null && f.getFileSize() > 0) {this.map.put(key, f);}}public FormFile getFile(String key) {return this.map.get(key);}/** * Method reset * @param mapping * @param request */public void reset(ActionMapping mapping, HttpServletRequest request) {// TODO Auto-generated method stub}public Map<String, FormFile> getMap() {return map;}public void setMap(Map<String, FormFile> map) {this.map = map;}}
Action:
public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception {// TODO Auto-generated method stubTtForm f = (TtForm)form;response.setCharacterEncoding("utf-8");PrintWriter out = response.getWriter();Set<Map.Entry<String, FormFile>> s = f.getMap().entrySet();out.println("共上传:"+s.size()+"个文件<br/>");for (Map.Entry<String, FormFile> mm : s) {FormFile ff = mm.getValue();out.println("FileName:"+ff.getFileName()+"<br/>");out.println("FileSize:"+ff.getFileSize()+"<br/>");out.println("=============<br/>");}return null;}
JSP:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <title>My JSP 'upload.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><script type="text/javascript">var index = 2;function add() {var form = document.forms[0];var input = document.createElement("input");input.type = "file";input.name = "file(file"+index+")";form.insertBefore(input,form.elements[form.elements.length - 1]);form.insertBefore(document.createElement("br"),form.elements[form.elements.length - 1]);index ++;}</script> </head> <body> <input type="button" value="添加上传文件" onclick="add()"/> <html:form action="/tt" method="post" enctype="multipart/form-data"> <html:file property="file(file1)"></html:file> <br/> <html:submit></html:submit> </html:form> </body></html>
- Struts 1.2 批量上传。
- Struts批量上传
- struts批量上传文件
- struts批量上传文件
- struts 1.2 上传文件
- 批量上传
- 批量上传
- Struts上传
- Struts 上传
- struts 2批量上传文件技术总结,为自己的开发生涯多做一点贡献。
- Struts 2 批量更新
- struts 1.2 文件上传与下载
- 文件上传,支持批量上传
- 上传图片、批量上传图片
- 批量上传图片
- php 批量 上传
- 批量上传不同图片
- 简单的批量上传
- java中的io系统总结
- 这个教程实在是太强悍了,大家都来一饱眼福吧
- 最新版50/100人民币,先睹为快(4张)
- linux下的文件和目录管理自我总结
- [转]关于EOF和getchar()
- Struts 1.2 批量上传。
- 程序员修炼之道---途径总纲
- 一个优化分析的例子
- EXT使用问题-动态创建tabPanel页面
- 设计模式之Iterator
- 设计模式之Memento——系统篇
- PHP常用字符串处理函数与ASP对照
- 图解 Linux 内存管理 -- 线性空间与物理内存
- 360度无缝全景壁纸