修改数据库文件地址存储相对路径
This commit is contained in:
@@ -26,7 +26,6 @@ public class DownLoadServlet extends HttpServlet {
|
||||
String address = projectService.selectProById(projectId).getFileAddress();
|
||||
String[] liss = address.split("\\\\");
|
||||
String fileName = liss[liss.length - 1];
|
||||
System.out.println(fileName);
|
||||
//本地需要进行转码,linux服务器使用就会出现下载乱码
|
||||
//fileName = new String(fileName.getBytes("iso8859-1"),"UTF-8");
|
||||
// System.out.print("转码后"+fileName);
|
||||
@@ -38,8 +37,6 @@ public class DownLoadServlet extends HttpServlet {
|
||||
//得到要下载的文件
|
||||
File file = new File(fileSaveRootPath + File.separator + fileName);
|
||||
//File file = new File(fileName);
|
||||
System.out.println(file);
|
||||
System.out.print("\n");
|
||||
// 浏览器请求响应转码防止乱码
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
@@ -51,7 +48,7 @@ public class DownLoadServlet extends HttpServlet {
|
||||
}
|
||||
//处理文件名
|
||||
String realname = fileName.substring(fileName.indexOf("_") + 1);
|
||||
System.out.println(realname);
|
||||
// System.out.println(realname);
|
||||
//设置响应头,控制浏览器下载该文件
|
||||
response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
//读取要下载的文件,保存到文件输入流
|
||||
|
@@ -45,6 +45,10 @@ public class UploadHandleServlet extends HttpServlet {
|
||||
String savePath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload");
|
||||
savePath= this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload").replace("\\out\\artifacts\\helloGithub_war_exploded\\WEB-INF\\upload","\\web\\uploadFile");
|
||||
System.out.println(savePath);
|
||||
String needPath = "\\helloGithub\\web\\uploadFile";
|
||||
String relPath = savePath.substring(savePath.length()-needPath.length(),savePath.length());
|
||||
|
||||
System.out.println(relPath);
|
||||
//上传时生成的临时文件保存目录
|
||||
String tempPath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"tmp");
|
||||
File tmpFile = new File(tempPath);
|
||||
@@ -164,7 +168,7 @@ public class UploadHandleServlet extends HttpServlet {
|
||||
message = "文件上传成功!";
|
||||
if(userName != null)
|
||||
{
|
||||
userService.updateUserAv(userName,realSavePath+"\\"+saveFilename);
|
||||
userService.updateUserAv(userName,relPath+"\\"+saveFilename);
|
||||
System.out.println("123");
|
||||
}
|
||||
|
||||
|
@@ -46,7 +46,8 @@ public class commitProjectFileServlet extends HttpServlet {
|
||||
//得到上传文件的保存目录,将上传的文件存放于WEB-INF目录下,不允许外界直接访问,保证上传文件的安全
|
||||
String savePath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload");
|
||||
savePath= this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload").replace("\\out\\artifacts\\helloGithub_war_exploded\\WEB-INF\\upload","\\web\\projectFile");
|
||||
System.out.println(savePath);
|
||||
String needPath = "\\helloGithub\\web\\uploadFile";
|
||||
String relPath = savePath.substring(savePath.length()-needPath.length(),savePath.length());
|
||||
//上传时生成的临时文件保存目录
|
||||
String tempPath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"tmp");
|
||||
File tmpFile = new File(tempPath);
|
||||
@@ -164,7 +165,7 @@ public class commitProjectFileServlet extends HttpServlet {
|
||||
//删除处理文件上传时生成的临时文件
|
||||
item.delete();
|
||||
message = "文件上传成功!";
|
||||
num = projectService.updateProject(projectName,realSavePath+"\\"+saveFilename);
|
||||
num = projectService.updateProject(projectName,relPath+"\\"+saveFilename);
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -57,13 +57,6 @@ public class commitProjectServlet extends HttpServlet {
|
||||
String []categoryIdList1 = categoryIdList.split(",");
|
||||
List<String> categoryIdList2 = Arrays.asList(categoryIdList1);
|
||||
|
||||
System.out.println(username);
|
||||
System.out.println(projectName);
|
||||
System.out.println(projectIco);
|
||||
System.out.println(projectUrl);
|
||||
System.out.println(projectTitle);
|
||||
System.out.println(projectDescription);
|
||||
System.out.println(categoryIdList);
|
||||
List<Integer> integers = new ArrayList<>();
|
||||
for (String s : categoryIdList2) {
|
||||
integers.add(Integer.parseInt(s));
|
||||
|
@@ -17,10 +17,6 @@ import java.nio.channels.Channels;
|
||||
@WebServlet("/retUserAv")
|
||||
public class retUserAvServlet extends HttpServlet {
|
||||
private UserService userService = new UserService();
|
||||
@Override
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
@@ -36,8 +32,13 @@ public class retUserAvServlet extends HttpServlet {
|
||||
userEntity=userService.selectUserByName(username);
|
||||
if(userEntity != null)
|
||||
{
|
||||
String savePath = this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload");
|
||||
savePath= this.getServletContext().getRealPath(File.separator+"WEB-INF"+File.separator+"upload").replace("\\out\\artifacts\\helloGithub_war_exploded\\WEB-INF\\upload","\\web\\projectFile");
|
||||
String needPath = "\\helloGithub\\web\\uploadFile";
|
||||
String relPath = savePath.substring(0,savePath.length()-needPath.length());
|
||||
String uri = userEntity.getUserAvatar();
|
||||
FileInputStream fis = new FileInputStream (uri);
|
||||
relPath = relPath+uri;
|
||||
FileInputStream fis = new FileInputStream (relPath);
|
||||
String type = userEntity.getUserAvatar().substring(userEntity.getUserAvatar().lastIndexOf(".")+1);
|
||||
int size = fis.available();
|
||||
if(size != 0)
|
||||
|
Reference in New Issue
Block a user