VereMVC 之 单文件上传

http://www.verejava.com/?id=1699040969622

1.打开 Eclipse 新建一个 test 项目   Eclipse -> File -> New -> Dynamic Web Project 


2.在 test/WebContent  下面新建一个 fileupload.jsp 文件 

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%
String fileName="";
if(request.getAttribute("fileName")!=null)
{
	fileName=request.getAttribute("fileName").toString();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
 <img src="upload/<%=fileName %>" />

 <form action="fileupload!add" method="post"  enctype="multipart/form-data" >
 	<input type="file" name="picture" />
 	
 	<input type="submit" name="submit" value="submit" />
 </form>
</body>
</html>



3.在 test/src  下面新建一个 com.test.action.FileUploadAction 类 

package com.test.action;

import java.io.File;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.vere.mvc.ServletActionContext;
import com.vere.mvc.util.CFile;
import com.vere.mvc.util.CParam;

public class FileUploadAction {
	
	public String execute()
	{
		
		return "success";
	}
	
	public String add()
	{
		HttpServletRequest request=ServletActionContext.getRequest();
		File picture=CParam.getFile(request, "picture");
		
		String dest=request.getRealPath("/upload")+"/"+picture.getName();
		CFile.save(picture,dest);
		
		request.setAttribute("fileName", picture.getName());
		return execute();
	}

}



4.在 test/src/VereMVC.xml  里面配置Action 

<?xml version="1.0" encoding="UTF-8"?>
<VereMVC>
	<constant name="charset"  value="utf-8" />
	<constant name="developMode"  value="true" />
	<constant name="language"  value="en_US" />
	

    <action name="fileupload" class="com.test.action.FileUploadAction">
      <result name="success">/fileupload.jsp</result>
    </action>
</VereMVC>



5.在 浏览器地址栏输入 http://localhost/test/fileupload 

http://www.verejava.com/?id=1699040969622

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值