-
[置顶]软件接口设计怎么做?前后端分离软件接口设计思路
本文关于软件接口设计怎么做?前后端分离软件接口设计思路。好的系统架构离不开好的接口设计,因此,真正懂接口设计的人往往是软件设计队伍中的稀缺型人才。为什么在接口制定标准中说:一流的企业做标准,二流的企业...
-
[置顶]接口管理如何做?接口实现版本管理的意义和最佳方法
本文关于接口管理如何做?接口实现版本管理的意义和最佳方法。API版本管理的重要性不言而喻,对于API的设计者和使用者而言,版本管理都有着非常重要的意义。下面会从WEB API 版本管理的角度提供几种常...
-
[置顶]实现API管理系统的关键
下面将通过几个关键词的形式说明API管理的重要性和未来的实现方式。1.生命周期管理在整个API生命周期中更深入地集成所有工具将进一步提高生命周期循环的速度,而且更重要的是提供满足消费者需求的API。这...
-
";
String desc = photo.getDesc();
String delStr = "删除";
String downStr = "下载";
out.println("
out.println("
out.println("
out.println("
out.println("
out.println("
+ "
out.println("
}
out.println("
out.println("
out.println("
out.println(" ");
out.println("");
out.flush();
out.close();
}
}
删除文件-DelServlet.java
package cn.hncu.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hncu.domain.PhotoModel;
import cn.hncu.photoDao.Dao.PhotoDao;
import cn.hncu.photoDao.factory.PhotoDaoFactory;
public class DelServlet extends HttpServlet {
//注入
private PhotoDao dao = PhotoDaoFactory.getPhotoDao();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uuid = request.getParameter("uuid");
String ip = request.getRemoteAddr();
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
PhotoModel photo = dao.getSingleByUuid(uuid);
if(photo!=null){
if(!photo.getIp().equals(ip)){
out.print("
out.print("返回上一页 ");
return ;
}
//1.删除数据库中的信息
boolean boo = dao.deleteXml(uuid);
if(boo){
String fileName = "photos/"+photo.getDir()+"/"+photo.getUuid()+photo.getExt();
String pathFileName = getServletContext().getRealPath(fileName);
if(dao.deleteFile(pathFileName)){
//重定向到相册页面
response.sendRedirect("/myPhoto/cloudPhoto?pwd=chx");
}else{
out.print("
out.print("返回上一页 ");
}
}else{
out.print("
out.print("返回上一页 ");
}
}
}
}
下载文件-DownServlet.java
package cn.hncu.servlets;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.hncu.domain.PhotoModel;
import cn.hncu.photoDao.Dao.PhotoDao;
import cn.hncu.photoDao.factory.PhotoDaoFactory;
public class DownServlet extends HttpServlet {
private PhotoDao dao = PhotoDaoFactory.getPhotoDao();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uuid = request.getParameter("uuid");
System.out.println(uuid);
PhotoModel photo = dao.getSingleByUuid(uuid);
System.out.println(photo);
if(photo!=null){
//设置响应头--内容接收程序--浏览器看到这个响应头,就会把它认为的下载程序打开
//(如果识别迅雷那么就会自动打开迅雷,如果没有则会打开一个“文件另存为”的对话框)
response.setContentType("application/force-download");
String realName = photo.getRealName();
String agent = request.getHeader("User-Agent");
System.out.println(agent);
if(agent.indexOf("Mozilla")!=-1){//火狐浏览器
response.setHeader("Content-Disposition" alt="自己动手写一个java版简单云相册" title="自己动手写一个java版简单云相册" width="200" height="150">