多文件上传
来源:互联网 发布:东方财富 数据 编辑:程序博客网 时间:2024/06/11 12:51
struts,DynaActionForm,数组,文件上传
源代码 2007-11-16 14:50:23 阅读44 评论0 字号:大中小
1. JSP页,文件上传,表单中有同名的属性
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for DynaActionForm form</title>
</head>
<body>
<html:form action="/user.do" method="POST" enctype="multipart/form-data">
userId : <html:text property="userId"/><br/>
salary : <html:text property="salary"/><br/>
<html:multibox property="hob" value="Computer" />Computer
<html:multibox property="hob" value="Ball" />Ball
<html:multibox property="hob" value="Book" />Book<br>
<html:file property="file"></html:file>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
2. 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 type="org.apache.struts.action.DynaActionForm">
<form-property type="java.lang.String" />
<form-property type="java.lang.Double" />
<form-property type="java.lang.String[]" />
<form-property type="org.apache.struts.upload.FormFile"/>
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="userForm"
input="/user.jsp"
path="/user"
scope="request"
type="com.sun.form.struts.action.UserAction">
<forward path="/ok.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.sun.form.struts.ApplicationResources" />
</struts-config>
3. UserAction.java
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.sun.form.struts.action;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.upload.FormFile;
import org.apache.struts.util.ModuleException;
/**
* MyEclipse Struts
* Creation date: 11-02-2006
*
* XDoclet definition:
* @struts.action path="/user" input="/user.jsp" scope="request" validate="true"
* @struts.action-forward path="/ok.jsp"
*/
public class UserAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm userForm = (DynaActionForm) form;// TODO Auto-generated method stub
String userId=userForm.getString("userId");
double salary=Double.parseDouble(userForm.get("salary").toString());
String []phone=userForm.getStrings("hob");
String dir=servlet.getServletContext().getRealPath("/photo");
System.out.println(phone[0]);
System.out.println(phone[1]);
FormFile file=(FormFile)userForm.get("file");
InputStream streamIn;
try {
streamIn = file.getInputStream();
OutputStream streamOut=new FileOutputStream(dir+"/"+file.getFileName());
int bytesRead=0;
byte[] buffer=new byte[8192];
while((bytesRead=streamIn.read(buffer,0,8192))!=-1)
{
streamOut.write(buffer,0,bytesRead);
}
streamOut.close();
streamIn.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
new ModuleException("error.exception");
} catch (IOException e) {
// TODO Auto-generated catch block
new ModuleException("error.exception");
}
file.destroy();
//System.out.println(userId);
return null;
}
}
- 文件上传(多文件)
- asp.net文件上传,多文件上传。
- 单文件上传、多文件上传
- struts2文件上传与多文件上传
- 单文件上传和多文件上传
- PHP文件上传功能 -- 多文件上传
- struts2文件上传(多文件上传)
- SpringMVC文件上传 多文件上传实例
- Struts2之文件上传,多文件上传
- SpringMVC文件上传 多文件上传实例
- 文件上传及多文件上传
- Spring boot 文件上传(多文件上传)
- Struts文件上传--2.多文件上传
- spring boot文件上传【多文件上传】
- FastDFS上传文件二 : 多文件上传
- 多文件上传
- 单/多文件上传
- 多个文件上传
- struts-config.xml 配置模板
- web.xml 配置模板
- basedao
- Android 远程调试 JNI 实现
- 使用cwRsync实现windows下文件定时同步(备份)
- 多文件上传
- 多文件上传
- struts 动态多文件上传
- LINUX下安装ORACLE为什么要设置环境变量啊
- 在eclipse上开发Android应用程序
- operator->重载问题总结(转)
- 读书笔记 《深度探索c++对象模型》 (2)
- 今天7月第一天,开个好头吧~
- linux 下C语言实现 读取网卡速度