Nginx增加mime类型 修改mime type类型默认打开方式的方法
Nginx的mime type Nginx 会根据mime type定义的对应关系来告诉浏览器如何处理服务器传给浏览器的这个文件,是打开还是下载;如果Web程序没设置,
Nginx也没对应文件的扩展名,
public class Cookie1 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); //获得客户端的所有的Cookie Cookie[] cookies=request.getCookies(); //从Cookie中找出存储最后登录时间的Cookie //Cookie是一个键值对,而且键和值都是String的 if(cookies!=null){ for(int i=0;i<cookies.length;i++){ String name = cookies[i].getName();//获得Cookie的name if("lastAccessTime".equals(name)) { String time = cookies[i].getValue();//获得最后登录时间,时间是字符串类型的 long t = Long.parseLong(time); out.println("上次登录时间为:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(t))); } } } //在页面上写一个删除的链接毗邻到DelCookie上删除cookie out.println("<a href='"+request.getContextPath()+"/servlet/delcookie'>删除Cookie</a>"); //把这次的登录时间以Cookie的形式发送给客户端 //确立Cookie Cookie cookie = new Cookie("lastAccessTime", System.currentTimeMillis()+""); cookie.setMaxAge(60*15);//Cookie 被存储到磁盘了 cookie.setPath(request.getContextPath());// /day35_cookie 只要是路径以 /day35_cookie开头的都可以吸收到Cookie //cookie.setPath("/");// /day35_cookie //把cookie发送给客户端 response.addCookie(cookie); /* * Cookie默认存储在浏览器的内存,浏览器一旦关闭,Cookie全都没了 * setMaxAge(time)设置Cookie的最大存活时间,默认单元是秒 * setMaxAge(-1);默认是-1,浏览器一旦关闭,Cookie全都没了 * setMaxAge(0):浏览器不关闭,Cookie也没了 * setMaxAge(正数) * * 知足什么条件客户端会把Cookie发给服务器端? * 被接见资源的路径前边要匹配 * http://localhost:8080/day35_cookie/servlet/cookie1 * http://localhost:8080/day35_cookie/servlet/cookie2 */ } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } |
删除cookie:
public class DelCookie extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); //删除Cookie Cookie cook = new Cookie("lastAccessTime", ""); cook.setMaxAge(0); //设置path,否则可能会错删 cook.setPath(request.getContextPath()); response.addCookie(cook); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } } |
php上传文件 $_FILES['']['type']的值
先来看一个函数: