吴方东ID:joejoe1991
133次访问,排名2万外好友61人,关注者110
joejoe1991的文章
原创 2 篇
翻译 0 篇
转载 0 篇
评论 0 篇
最近评论
文章分类
收藏
    相册
    存档
    订阅我的博客
    XML聚合  FeedSky

    原创 Struts 1.2 批量上传。收藏

     | 旧一篇: 在JVM退出的时候,执行一段特定的代码。

    网上找的代码不知道为啥都不能用,自己写一个简陋点的。 

    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 stub
    
    		return 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 stub
    
    		TtForm 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>
    
    

    发表于 @ 2008年06月21日 10:40:00|评论(loading...)|编辑|收藏

     | 旧一篇: 在JVM退出的时候,执行一段特定的代码。

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © joejoe1991