seasar2的多文件上传
来源:互联网 发布:数车工艺品图纸及编程 编辑:程序博客网 时间:2024/05/16 12:28
备忘用。
JSP:
<table border="0">
<c:set var="fileCnt" value="0" />
<c:forEach varStatus="unpan" begin="${fileCnt}" end="4">
<tr>
<th>文件上传</th>
<td>
<input type="file" name="gzUpfiles[${unpan.index}]" class="file" />
</td>
</tr>
</c:forEach>
</table>
<c:set var="fileCnt" value="0" />
<c:forEach varStatus="unpan" begin="${fileCnt}" end="4">
<tr>
<th>文件上传</th>
<td>
<input type="file" name="gzUpfiles[${unpan.index}]" class="file" />
</td>
</tr>
</c:forEach>
</table>
Action:
public class Gg0201G01Action {
public class Gg0201G01Action {
@ActionForm
@Resource
protected Gg0201G01Form gg0201G01Form;
@Resource
protected Gg0201G01Form gg0201G01Form;
@Resource
protected Gg0201G01Logic gg0201G01Logic;
protected Gg0201G01Logic gg0201G01Logic;
/**
* 実行メソッド
*
* @return
*/
@Execute(validator = false)
public String index() throws Exception {
return "/gg/gg0201g01.jsp";
}
* 実行メソッド
*
* @return
*/
@Execute(validator = false)
public String index() throws Exception {
return "/gg/gg0201g01.jsp";
}
/**
* 登録処理
*
* @return
*/
@Execute(validator = false)
public String regist() {
/* 登録処理 */
gg0201G01Logic.regist();
return "/gg/gg0201G01.jsp";
}
}
* 登録処理
*
* @return
*/
@Execute(validator = false)
public String regist() {
/* 登録処理 */
gg0201G01Logic.regist();
return "/gg/gg0201G01.jsp";
}
}
Form:
public class Gg0201G01Form {
private static final long serialVersionUID = 1L;
// アップロード用画像ファイル
public FormFile[] gzUpfiles = {};
}
Logic:
public class Gg0101G02Logic {
@Resource
protected Gg0101G02Form gg0101G02Form;
protected Gg0101G02Form gg0101G02Form;
/**
* 画像の登録処理
*
* @param workDir
* @param uploadDir
*/
public boolean imgRegExecute( ) {
* 画像の登録処理
*
* @param workDir
* @param uploadDir
*/
public boolean imgRegExecute( ) {
// ログ出力(処理開始)
logger.debug("画像登録開始");
logger.debug("画像登録開始");
// 登録ワークDirを取得する
String work_reg_dir = "c://work";
for (int Index = 0; Index < gg0201G01Form.gzUpfiles.length; Index++) {
FormFile file = gzUpfiles[Index];
if (file.getFileSize() > 0) {
/* 画像登録処理 */
try {
// 画像ファイルをワークに保存
bRtn = upLoad(file, work_reg_dir, "newFileName.jpg");
if (!bRtn) {
break;
}
} catch (FileNotFoundException e) {
bRtn = false;
logger.error(e.getMessage(), e);
break;
} catch (IOException e) {
bRtn = false;
logger.error(e.getMessage(), e);
break;
}
String work_reg_dir = "c://work";
for (int Index = 0; Index < gg0201G01Form.gzUpfiles.length; Index++) {
FormFile file = gzUpfiles[Index];
if (file.getFileSize() > 0) {
/* 画像登録処理 */
try {
// 画像ファイルをワークに保存
bRtn = upLoad(file, work_reg_dir, "newFileName.jpg");
if (!bRtn) {
break;
}
} catch (FileNotFoundException e) {
bRtn = false;
logger.error(e.getMessage(), e);
break;
} catch (IOException e) {
bRtn = false;
logger.error(e.getMessage(), e);
break;
}
}
}
}
logger.debug("画像登録終了");
return bRtn;
}
return bRtn;
}
/**
* 画像のアップロード処理
*
* @param file
* @param uploadDir
* @param newFileName
* @return
* @throws FileNotFoundException
* @throws IOException
*/
private boolean upLoad(FormFile file, String uploadDir, String newFileName) throws FileNotFoundException, IOException {
boolean bRtn = true;
File dirPath;
try {
/* ディレクトリ作成 */
dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
* 画像のアップロード処理
*
* @param file
* @param uploadDir
* @param newFileName
* @return
* @throws FileNotFoundException
* @throws IOException
*/
private boolean upLoad(FormFile file, String uploadDir, String newFileName) throws FileNotFoundException, IOException {
boolean bRtn = true;
File dirPath;
try {
/* ディレクトリ作成 */
dirPath = new File(uploadDir);
if (!dirPath.exists()) {
dirPath.mkdirs();
}
// 書き込み
UploadUtil.write(dirPath.getPath() + File.separator + newFileName, file);
} catch (Exception e) {
bRtn = false;
logger.error(e.getMessage(), e);
}
UploadUtil.write(dirPath.getPath() + File.separator + newFileName, file);
} catch (Exception e) {
bRtn = false;
logger.error(e.getMessage(), e);
}
return bRtn;
}
}
}
- seasar2的多文件上传
- seasar2
- Seasar2之$的讲解-yellowcong
- 多文件上传的例子
- webwork的多文件上传
- Struts2的多文件上传
- struts1的多文件上传
- struts的多文件上传
- Struts2多文件的上传
- PHP的多文件上传
- 最新的文件上传模型,支持多文件上传
- struts2的文件上传(1):每次上传多个文件
- SpringMVC 文件上传配置,多文件上传,使用的MultipartFile
- SpringMVC 文件上传配置,多文件上传,使用的MultipartFile
- SpringMVC 文件上传配置,多文件上传,使用的MultipartFile
- SpringMVC 文件上传配置,多文件上传,使用的MultipartFile
- SpringMVC 文件上传配置,多文件上传,使用的MultipartFile
- SpringMVC 文件上传配置,多文件上传,使用的MultipartFile
- 嵌入式系统学习步骤
- 各种C++库
- directx 摄像头控制
- 设计模式-------建造者
- 文件系统执行过程【草稿】
- seasar2的多文件上传
- oracle函数使用java类的方法
- Linux人才需求高涨 Unix与Win需求持平
- hibernate组建映射
- 截屏工具____FastStone Capture (屏幕截图)V6.5 Final绿色汉化特别版
- 求助,这种mD5是如何解密? 或者是什么加密方式
- 跟 LFJ 的赌约 以及LFJ的回家
- .PLY文件格式剖析(二)
- 取指定字符串的指定长度