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.