Java文件上传获取不到客户端文件
来源:百度知道 编辑:UC知道 时间:2024/05/23 16:26:16
JSP代码:
test1.jsp
<form action="test2.jsp" name="form1">
<div>
<input type="file" name="my-file" id="my-file" onchange="inputFileOnChange();" />
<input type="submit" name="sub" value="sub">
</div>
</form>
=============================================================
test2.jsp
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
//String filePath=request.getParameter("p_img");
String filePath=request.getParameter("my-file");
UploadImg uimg=new UploadImg();
System.out.println(filePath);
String sPath=application.getRealPath("");
boolean bool=uimg.
必须要现判断文件路径是否存在的,否则需要创建个文件,没这个文件,肯定会报错。
/**
* 加密文件
*
* @param fileName
* @param date
* @param plainFilePath 明文文件路径路径
* @param filepath
* @return
* @throws Exception
*/
public static String encodeAESFileUploadByFtp(String plainFilePath, String fileName, String date,String filepath) throws Exception {
FileInputStream fis = null;
ByteArrayOutputStream bos = null;
FTPClient ftpClient = new FTPClient();
String bl = "false";
try {
fis = new FileInputStream(plainFilePath);
bos = new ByteArrayOutputStream(fis.available());
byte[] buffer = new byte[1024];
int count = 0;
while ((count = fis.read(buffer)) != -1) {
bos.write(buffer, 0, count);
}
bos.flush();
Log.