客户专线:135-1821-9792
服务热线:028-86922220
我们专注于高端品牌网站创意设计与开发
高端网站定制
品牌网站建设
企业官网建设
营销网站建设
集团网站建设
外贸网站建设
政府/门户信息
企业网站改版
响应式网站建设
企业形象设计
企业MP4宣传视频
网络营销推广
网站在线客服系统
域名注册
服务器/主机租赁
企业邮箱
微信公众号
微商城开发
微官网建设
小程序开发
品牌网站建设解决方案
营销网站解决方案
集团上市公司网站建设解决方案
政府机构类网站建设解决方案
网站定制建设解决方案
外贸网站建设解决方案
医药医疗网站解决方案
旅游网站解决方案
微信小程序定制开发解决方案
1.浏览器端:选择图片、提交表单,同时将图片发送给服务器
@WebServlet("/FileUploadServlet") @MultipartConfig //表示支持文件上传,否则获得null public class FileUploadServlet extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //1 普通字段 String username = request.getParameter("username"); System.out.println(username); //2 上传字段 Part part = request.getPart("image"); //2.1 获得文件名 // * IE --> C:\Users\liangtong\Desktop\heima.txt // * 其他浏览器 --> heima.txt String contentDisposition = part.getHeader("Content-Disposition"); System.out.println(contentDisposition); // * 截取文件名 int start = contentDisposition.indexOf("filename=") + 10; int end = contentDisposition.length() - 1; String fileName = contentDisposition.substring(start, end); // * 浏览器兼容 -- lastIndexOf() 如果没有获得返回 -1 fileName = fileName.substring( fileName.lastIndexOf("\\") + 1); System.out.println(fileName); //2.2 获得上传文件内容 InputStream is = part.getInputStream(); //2.3 将流写入到服务器文件中 // * 上传目录 String dir = this.getServletContext().getRealPath("/WEB-INF/upload"); File file = new File(dir , fileName); // * 流的对拷 FileOutputStream out = new FileOutputStream(file); byte[] buf = new byte[1024]; int len = -1; while( (len = is.read(buf)) != -1 ){ out.write(buf, 0, len); } out.close(); is.close(); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
售后响应及时
数据备份
价格公道精准
合作无风险