问题描述
- ssh后台怎么接受安卓和ios端发送文件怎么接受,
- 我后台用的ssh框架,在安卓和ios上传文件的时候老接受不到文件,求方法,
解决方案
前端发送multipart格式的数据,你在后台接收一下这个,并转化一下,springMVC中用multipart接收,strtus2中你就在对应的action中写private File myFile;//提交文件名称,然后set/get,这样你就得到file类型的文件了,在写到服务器中
解决方案二:
有例子么?你这种我也试了的
解决方案三:
struts.xml 代码如下:
<!DOCTYPE struts PUBLIC
-//Apache Software Foundation//DTD Struts Configuration 2.0//EN""
http://struts.apache.org/dtds/struts-2.0.dtd"">
<package name =""fileUploadDemo"" extends =""struts-default""> <action name =""fileUpload"" class =""org.qiujy.web.struts2.FileUploadAction"">
<param name=""savePath"">/upload</param> <result name =""success"">/succ.jsp</result> </action ></package >
jsp代码:
<%@ page language=""java"" contentType=""text/html; charset=UTF-8""%>
Struts2 File Upload
文件标题:
选择文件:
action 代码:
package org.qiujy.web.struts2;
import java.io.IOException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletContext;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
*处理文件上传的Action类
*@authorqiujy
*@version1.0
*/
public class FileUploadAction extends ActionSupport {
// private static final int BUFFER_SIZE = 16 * 1024;
// 文件标题
private String title;
// 上传文件域对象
private File upload;
// 上传文件名
private String uploadFileName;
// 上传文件类型
private String uploadContentType;
// 保存文件的目录路径(通过依赖注入)
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
@Overridepublic String execute() throws Exception { //根据服务器的文件保存地址和原文件名创建目录文件全路径 ServletContext svct = ServletActionContext.getServletContext(); System.out.println(upload); if(upload != null) { String dataDir = svct.getRealPath(""/upload""); File saveFile = new File(dataDiruploadFileName); upload.renameTo(saveFile); } return SUCCESS;}
}
网上给你搜的,这种代码有的是,你自己找找就行,另外你测试的时候多换换浏览器试试