SSH文件上传代码片段
一、文件上传限制:
在web.xml中配置Struts前端控制器时,设置初始化参数:如下图所示

二、controller代码
@Namespace("/")
@ParentPackage("struts-default")
@Scope("prototype")
@Controller
public class ImageAction extends ActionSupport {
private File imgFile;
public void setImgFile(File imgFile) {
this.imgFile = imgFile;
}
private String imgFileFileName;
public void setImgFileFileName(String imgFileFileName) {
this.imgFileFileName = imgFileFileName;
}
@Action(value = "imageAction_upload")
public String upload() throws IOException {
Map<String,Object> map = new HashMap<>();
try {
String dirPath = "/upload/";
ServletContext servletContext = ServletActionContext.getServletContext();
String realPath = servletContext.getRealPath(dirPath);
String suffix = imgFileFileName.substring(imgFileFileName.lastIndexOf("."));
String fileName = UUID.randomUUID().toString().replaceAll("-","")+suffix;
File destFile = new File(realPath+"/"+fileName);
FileUtil.copyFile(imgFile,destFile);
String contextPath = ServletActionContext.getServletContext().getContextPath();
map.put("error",0);
map.put("url",contextPath+dirPath+fileName);
} catch (IOException e) {
map.put("error",1);
map.put("message",e.getMessage());
e.printStackTrace();
}
String json = JSONObject.fromObject(map).toString();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write(json);
return NONE;
}
}
SSH文件上传代码片段的更多相关文章
- servlet3.0获取参数与文件上传代码示例
转: servlet3.0获取参数与文件上传代码示例 2018年08月26日 20:25:35 苏凯勇往直前 阅读数:98 package com.igeek.servlet; import ...
- php文件上传代码解析
php文件上传代码解析 is_uploaded_file() //函数判断指定的文件是否是通过 HTTP POST 上传的,返回一个布尔值. $_FILES['upfile']['tmp_name' ...
- 实现Magento多文件上传代码功能开发
在Magento中上传单个文件很简单,可以直接在继承的Mage_Adminhtml_Block_Widget_Form类中直接添加如下组件Field: 对于图片: $fieldset->a ...
- (实用篇)php处理单文件、多文件上传代码分享
php处理 单文件.多文件上传实例代码,供大家参考,具体内容如下 后台处理文件submit_form_process.php <?php /************************** ...
- PHP文件上传代码和逻辑详解
文件上传的逐步完善------ [简单的上传:] <form action="upload.php" method="post" enctype= ...
- PHP 图片文件上传代码
通过 PHP,可以把文件上传到服务器.里面加入一些图片的判断,如果不加判断文件的类型就可以上传任意格式的文件. 为了网站的安全,肯定不让上传php文件,如果有人进入你的后台,上传了一个php文件,你的 ...
- PHP 图片文件上传代码分享
分享下php上传图片文件的一段代码,挺不错的. 通过 PHP,可以把文件上传到服务器.加入一些图片的判断,如果不加判断文件的类型就可以上传任意格式的文件. 当然了,会禁止上传php文件,以及其它程序代 ...
- ASP文件上传代码
在网上看到的代码,稍微有点问题,改了一下就可以了.Chrome下是可以用的,别的浏览器还没有确认. <% Response.Buffer = True Server.ScriptTimeOut= ...
- JavaWEB SSH文件上传
一.提交表单的<form> method属性必须为post 并且添加enctype="multipart/form-data" 属性 前台: <td>上传 ...
随机推荐
- Windows 如何完整备份驱动
软件:DriverBackUp 系统环境:Windows7 首先将DriverBackUp.exe放到桌面,然后运行,我们会看到提示信息提示我们驱动程序被备份到了D盘 然后我们会看到备份界面 这里我们 ...
- php 递归数据,三维数组转换二维
public function sortarea($area, $parent_id = 0, $lev = 1){ static $list; foreach($area as $v){ if($v ...
- SpringBoot idea maven打包war及运行war包
pom.xml修改打包类型pom改为war <artifactId>Test02</artifactId> <packaging>war</packaging ...
- datetime 模块
datetimo 模块和time模块类似,只不过直接帮你定好了格式 import datetime time =datetime.datetime.now() print(time,type(time ...
- 架构师养成记--35.redis集群搭建
前记:redis哨兵经验之谈.哨兵做主从切换可能要花费一两秒,这一两秒可能会丢失很多数据.解决方法之一是在java代码中做控制,try catch 到 链接断开的异常就sleep 一两秒钟再conti ...
- 性能测试 vs 负载测试 vs 压力测试
在做一些软件测试工作时,常常会被提及性能测试.负载测试.压力测试,这也是在软件测试方面最容易混淆的三个概念.之前和一个测试大牛聊天,他和我说常常面试一些测试人员会问一些这样的问题,大多人认为负载测试等 ...
- linux 将进程或者线程绑定到指定的cpu上
基本概念 cpu亲和性(affinity) CPU的亲和性, 就是进程要在指定的 CPU 上尽量长时间地运行而不被迁移到其他处理器,也称为CPU关联性:再简单的点的描述就将指定的进程或线程绑定到相应的 ...
- python全栈开发学习_内容目录及链接
python全栈开发学习_day1_计算机五大组成部分及操作系统 python全栈开发学习_day2_语言种类及变量 python全栈开发_day3_数据类型,输入输出及运算符 python全栈开发_ ...
- python全栈开发_day15_函数回调和模块
一:函数回调 def a(fn=None): print("run1") if fn: fn() print("run 2") def b(): print(& ...
- 【实战】某项目SQL注入引发的思考
数据包: 测试参数:username,测试payload: ' ' or '1'='1 ' or '1'='2 响应结果都未发生任何变化,借助sqlmap测试,结果一样: 尝试在or前面进行简单的fu ...