当前位置:首页 » 文件传输 » ssh框架上传
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

ssh框架上传

发布时间: 2022-11-29 18:38:46

❶ SSH框架实现文件上传和下载

我给你提供思路,自己去实现。
1、你用的是SSH框架,spring有一个MultipartFile技术,支持单文件和多文件上传
2、下载直接用BufferedInputStream+BufferedOutputStream去实现就可以了。
这两个都是很好学的。挺简单的

❷ ssh框架上传图片与显示

页面的form
<formaction="indexDetail.action"method="post"enctype="multipart/form-data">
图片:<inputtype="file"name="file"/><br/>
<inputtype="submit"name="imageField"class="btn_imgimg_submit"value="提交"/>
</form>

后台代码

//上传文件
privateFilefile;
privateStringfileFileName;

Stringrealpath=ServletActionContext.getServletContext().getRealPath("/images/ask/");
if(!newFile(realpath).exists()){
newFile(realpath).mkdir();
}
String[]typechoose=fileFileName.split("\.");
intichoose=typechoose.length;
Stringtype=ichoose>1?typechoose[ichoose-1]:"";
SimpleDateFormatsmat=newSimpleDateFormat("yyyyMMddHHmmss");
Stringnewfilname=smat.format(newDate())+"."+type;
Stringpath=realpath+"/"+newfilname;
FileUtil.saveFile(path,file);

核心代码都在里面

❸ ssh框架如何判断上传附件不能大于9M

<interceptor-refname="fileUpload"><paramname="allowedTypes">image/png,image/gif,image/jpeg,image/jpg
</param><paramname="maximumSize">204800</param></interceptor-ref>

在struts2的配置文件中这样配置,限制上传文件类型,和上传大小,上面限制为2M的图片,
如果超过或者类型不对action里面方法会返回input这个字符串

❹ ssh框架ajaxFileUpload上传文件后文件变成tmp文件

上传的临时文件名都是tmp的
你可以把这个tmp文件拷贝你想要放的目录下面
至于你说tmp文件改名后打开也会提示不完整的问题
加个 out.flush(); 试试

❺ 上传文件只能上传2M以内的文件(ssh框架),求助!!

方法1:
struts2默认使用common-fileupload实现文件的上传,默认最大支持上传文件的大小为2M,
新建struts.properties 添加struts.multipart.maxSize=10000000大约为9.5M
那么问题又来了 为什么可以上传11M多点的文件呢?
方法2:在struts.xml 的<struts></struts>添加
<constant name="struts.multipart.maxSize" value="10000000"/>

❻ ssh框架 上传问题,怎么把上传的文件的名字和上传时间传到数据库的对应表里

可以把属性封装到一个javabean中,再把javabean的信息保存到数据库中

❼ java ssh框架中怎么上传图片

package com.lilian.framework.servlet;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.lilian.business.common.model.CmResource;
import com.lilian.framework.utils.FileLoadUtil;

/**
* 通用上传组件(可以使用uploadify等上传组件上传资源)
* @author Ares
*/
public class FileUploadServlet extends HttpServlet {

private static final long serialVersionUID = -7933946015372885027L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doProcess(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doProcess(request, response);
}

public void doProcess(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=utf-8");
// 保存后的文件名
String bornName = ""; //源文件名
String fileName = ""; //文件名
String fileFormat = ""; //文件格式
short fileType = 1; //文件类型
Long fileSize = 0l; //文件大小
String hostAddr = ""; //主机地址(主机IP/域名)
String virtualAddr = ""; //虚拟地址(相对路径)
String urlPath = ""; //URL地址(访问路径)

// 通过时间戳散列目录存储
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMM/ddHH/");
Date curDate = new Date(System.currentTimeMillis()); // 获取当前时间
String fileFolder = formatter.format(curDate);

hostAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.hostadd");

// virtualAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.virtualdir.image") + fileFolder;
String uploadType = request.getParameter("uploadType");
if(uploadType!=null && !uploadType.equals("")){
if(uploadType.equals("1")){
virtualAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.virtualdir.image") + fileFolder;
}else if(uploadType.equals("2")){
virtualAddr = FileLoadUtil.getKeyValueByKeyName("file.upload.virtualdir.config") + fileFolder;
}else{
response.getWriter().print("文件上传失败,上传类型不存在!");
return;
}
}else{
response.getWriter().print("文件上传失败,没有上传类型!");
return;
}

// urlPath = SystemLocation.getWebrootpath() + "/" + virtualAddr;
urlPath = hostAddr + virtualAddr;

// 文件存放的目录
// String savePath = FileUtil.getUploadFilePath();
String savePath = FileLoadUtil.getKeyValueByKeyName("file.upload.path") + virtualAddr;

// 这里还可以添加有业务规则的文件目录,比如允许每个用户有自己的上传文件目录
File tempDirPath = new File(savePath);
if (!tempDirPath.exists()) {
tempDirPath.mkdirs();
}

// 创建磁盘文件工厂
DiskFileItemFactory fac = new DiskFileItemFactory();
// 创建servlet文件上传组件
ServletFileUpload upload = new ServletFileUpload(fac);
// 设置charset为utf-8,上传中文文件名不会产生乱码
upload.setHeaderEncoding("UTF-8");

// 文件列表
List fileList = null;
// 解析request从而得到前台传过来的文件
try {
fileList = upload.parseRequest(request);
} catch (FileUploadException ex) {
ex.printStackTrace();
return;
}

// 遍历从前台得到的文件列表
Iterator<FileItem> it = fileList.iterator();
List<CmResource> cmResourceList = new ArrayList<CmResource>();
while (it.hasNext()) {
FileItem item = (FileItem) it.next();
if (!item.isFormField()) {
fileName = item.getName();
fileSize = item.getSize();
bornName = fileName.substring(0, fileName.lastIndexOf("."));
if (fileName == null || fileName.trim().equals("")) {
continue;
}

// 扩展名格式:
if (fileName.lastIndexOf(".") >= 0) {
fileFormat = fileName.substring(fileName.lastIndexOf(".")+1);
}

File file = null;
do {
// 生成文件名:
fileName = UUID.randomUUID().toString() + "." + fileFormat;
file = new File(savePath + fileName);
} while (file.exists());

File saveFile = new File(savePath + fileName);
try {
item.write(saveFile);
} catch (Exception e) {
e.printStackTrace();
}

System.out.println("***************************************************************");
System.out.println("bornName: " + bornName);
System.out.println("fileName: " + fileName);
System.out.println("fileFormat: " + fileFormat);
System.out.println("fileType: " + fileType);
System.out.println("fileSize: " + fileSize.longValue());
System.out.println("hostAdd: " + hostAddr);
System.out.println("virtualAddr: " + virtualAddr);
System.out.println("urlPath: " + urlPath);
System.out.println("imageURL: " + hostAddr + virtualAddr + fileName);
System.out.println("***************************************************************");

CmResource cmResource = new CmResource();
cmResource.setBornName(bornName);
cmResource.setFileName(fileName);
cmResource.setFileFormat(fileFormat);
cmResource.setFileType(fileType);
cmResource.setFileSize(fileSize);
cmResource.setHostAddr(hostAddr);
cmResource.setVirtualAddr(virtualAddr);
cmResource.setUrlPath(urlPath);
cmResourceList.add(cmResource);
}
}

// 将文件的 相对路径+源名称+文件大小 返回给response流。
request.setAttribute("cmResourceList", cmResourceList);
response.setContentType("text/html; charset=utf-8");
response.getWriter().print("文件上传成功!");
}
}
万能通用

❽ SSH框架上传文件名 NULL

用的
Struts2
.0吗?
看你接收文件名的方式比较像,这里文件名应该是uploadFileName,可能是你的大小写错了.
Struts2接收文件名的属性是
上传的参数名
+
FileName
注意还要生成其setter方法
---------------------------------------------------------
既然这里没写错那么就要检查你Action中上传部分的代码,看是否没有在上传时设置文件名,或将一个空值设置成为了文件名,可以在Action中打印一下这个uploadFileName,看值是否接收到

❾ SSH框架中,怎么实现大文件的二进制上传

做一个servlet,在web.xml里配置一下,上传的时候调这个。