• 大小: 41KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: Java
  • 标签:

资源简介

本资源是头像设置功能实现的源码,代码使用JSP/Servlet及AJAX实现

资源截图

代码片段和文件信息

/**
 * 
 * author : wubl
 * 
 * date: 2018/4/23
 * 
 */

package com.demo;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;

@MultipartConfig 
@WebServlet(“/PortraitServlet“)
public class PortraitServlet extends HttpServlet {

protected void doGet(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
response.setContentType(“application/text; charset=utf-8“);
PrintWriter out = response.getWriter();

final Part filePart = request.getPart(“headerImg“);  
        if (filePart == null) {  
            response.getWriter().print(“未指定文件“);  
            return;  
        }  
          
        if (filePart.getSize() > 1024 * 500) {  
            response.getWriter().print(“文件太大“);  
            return;  
        }  
        String filename = filePart.getSubmittedFileName();//获取上传文件名  
// System.out.println(filename);
String realPath = this.getServletContext().getRealPath(“/avatorImg“);  
System.out.println(realPath);
        //获取web目录的真实物理路径,文件将保存在upload文件夹下  
        File dir=new File(realPath);  
        if(!dir.exists()){  
            dir.mkdir();//如果目录不存在,则创建  
        }  
  
        filePart.write(realPath + “/“ + filename);//将文件写入磁盘  
              
        out.print(1);  
}


protected void doPost(HttpServletRequest request HttpServletResponse response) throws ServletException IOException {
// TODO Auto-generated method stub
doGet(request response);
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-04-22 21:03  HeadPortraitDemo\
     文件         842  2018-04-22 21:03  HeadPortraitDemo\.classpath
     文件         916  2018-04-22 21:03  HeadPortraitDemo\.project
     目录           0  2018-04-22 22:47  HeadPortraitDemo\.settings\
     文件         567  2018-04-22 21:03  HeadPortraitDemo\.settings\.jsdtscope
     文件          69  2018-04-22 22:47  HeadPortraitDemo\.settings\org.eclipse.core.resources.prefs
     文件         364  2018-04-22 21:03  HeadPortraitDemo\.settings\org.eclipse.jdt.core.prefs
     文件         500  2018-04-22 21:03  HeadPortraitDemo\.settings\org.eclipse.wst.common.component
     文件         345  2018-04-22 21:03  HeadPortraitDemo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2018-04-22 21:03  HeadPortraitDemo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2018-04-22 21:03  HeadPortraitDemo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2018-04-22 21:03  HeadPortraitDemo\build\
     目录           0  2018-04-23 12:59  HeadPortraitDemo\build\classes\
     目录           0  2018-04-23 12:59  HeadPortraitDemo\build\classes\com\
     目录           0  2018-04-23 12:59  HeadPortraitDemo\build\classes\com\demo\
     文件        2512  2018-04-23 14:06  HeadPortraitDemo\build\classes\com\demo\PortraitServlet.class
     目录           0  2018-04-23 12:59  HeadPortraitDemo\src\
     目录           0  2018-04-23 12:59  HeadPortraitDemo\src\com\
     目录           0  2018-04-23 12:59  HeadPortraitDemo\src\com\demo\
     文件        1949  2018-04-23 14:06  HeadPortraitDemo\src\com\demo\PortraitServlet.java
     目录           0  2018-04-23 13:01  HeadPortraitDemo\WebContent\
     目录           0  2018-04-23 13:01  HeadPortraitDemo\WebContent\css\
     文件        1668  2018-04-22 22:49  HeadPortraitDemo\WebContent\css\portrait.css
     文件         990  2018-04-27 23:11  HeadPortraitDemo\WebContent\index.jsp
     目录           0  2018-04-23 13:02  HeadPortraitDemo\WebContent\js\
     文件       86927  2018-02-03 16:25  HeadPortraitDemo\WebContent\js\jquery-3.3.1.min.js
     文件        2297  2018-04-23 21:34  HeadPortraitDemo\WebContent\js\portrait.js
     目录           0  2018-04-22 21:03  HeadPortraitDemo\WebContent\meta-INF\
     文件          39  2018-04-22 21:03  HeadPortraitDemo\WebContent\meta-INF\MANIFEST.MF
     目录           0  2018-04-22 22:32  HeadPortraitDemo\WebContent\WEB-INF\
     目录           0  2018-04-22 21:03  HeadPortraitDemo\WebContent\WEB-INF\lib\
............此处省略1个文件信息

评论

共有 条评论

相关资源