首页 web前端 js教程 Ajax配合Spring实现文件上传功能代码

Ajax配合Spring实现文件上传功能代码

Jan 01, 2018 pm 07:38 PM
ajax spring 文件

最近在开发一个可以上传图片到服务器的web表面页面,下面给大家分享需求和实现思路还有ajax源码,对ajax感兴趣的的朋友参考下Ajax配合Spring实现文件上传功能哦!

由于项目需要,开发一个可以上传图片到服务器的web表单页面。

一、 需求

Web表单页面,可以通过表单上传图片以及其他文字信息。

二、 图片上传的流程

之前没有做过这类页面,通过查询资料。发现比较常见的做法,是先将图片上传到服务器端的某个文件目录下,服务器向前台返回图片的存储路径;之后,前台将图片存储路径以及其他表单信息一起提交到服务器,所有的表单信息存储在数据库中。

三、 方法

由于项目需要,我这里介绍两种图片上传方法,第一种是使用ajax对一个图片直接上传;第二种是先在前台将图片切割为较小的文件,之后使用ajax分别上传图片到服务器,服务器实现对文件的拼接。(方法二适合较大文件的上传)下面我分别对两种方法做介绍。

方法一: 直接上传

1 html页面


<pre name="code" class="html"><!DOCTYPE html> 
<head></head> 
<body> 
<form id="uploadForm" action="/PicSubmit/form" method="post" enctype="multipart/form-data" onsubmit="return submit_check()" class="bootstrap-frm" >
<input id = "sid" type = "text" name="name" />
<pre name="code" class="html"><input id = "fileImage" type = "file" name="filename" />
<input id = "addressid" type = "hidden" name="address" />
<input id="ajaxsub" type="button" class="button" value="上传图片" onclick="fileUpload()<span style="font-family: Arial, Helvetica, sans-serif;">" /> </span>
<input type="submit" class="button" value="提交表单" /> 
<input type="reset" class="button" value="重置表单" /> 

 

 
这一部分需要注意的是,form表单的enctype属性必须设置为“multipart/form-data”,在Html5中,如果需要多张图片一起上传,可以在 标签中,增加multiple属性,例如:


2 js

(1)js使用ajax提供的ajaxfileupload.js库。这个库使用起来还是比较方便的,和普通的ajax函数使用方法几乎相同。首先,需要ajaxfileupload.js库文件。这里需要注意,我之前在网上下载了一个ajaxfileupload.js文件不能用,浪费了很长时间,我直接把js库文件粘贴到这里,方便分享。

// JavaScript Document
// ajax file uplaod 
jQuery.extend({ 
  createUploadIframe: function(id, uri) 
  { 
    //create frame 
    var frameId = &#39;jUploadFrame&#39; + id; 
    if(window.ActiveXObject) { 
      var io = document.createElement(&#39;<iframe id="&#39; + frameId + &#39;" name="&#39; + frameId + &#39;" />&#39;); 
      if(typeof uri== &#39;boolean&#39;){ 
        io.src = &#39;javascript:false&#39;; 
      } 
      else if(typeof uri== &#39;string&#39;){ 
        io.src = uri; 
      } 
    } 
    else { 
      var io = document.createElement(&#39;iframe&#39;); 
      io.id = frameId; 
      io.name = frameId; 
    } 
    io.style.position = &#39;absolute&#39;; 
    io.style.top = &#39;-1000px&#39;; 
    io.style.left = &#39;-1000px&#39;; 
    document.body.appendChild(io); 
    return io; 
  }, 
  createUploadForm: function(id, fileElementId) 
  { 
    //create form 
    var formId = &#39;jUploadForm&#39; + id; 
    var fileId = &#39;jUploadFile&#39; + id; 
    var form = jQuery(&#39;<form action="" method="POST" name="&#39; + formId + &#39;" id="&#39; + formId + &#39;" enctype="multipart/form-data"></form>&#39;); 
    var oldElement = jQuery(&#39;#&#39; + fileElementId); 
    var newElement = jQuery(oldElement).clone(); 
    jQuery(oldElement).attr(&#39;id&#39;, fileId); 
    jQuery(oldElement).before(newElement); 
    jQuery(oldElement).appendTo(form); 
    //set attributes 
    jQuery(form).css(&#39;position&#39;, &#39;absolute&#39;); 
    jQuery(form).css(&#39;top&#39;, &#39;-1200px&#39;); 
    jQuery(form).css(&#39;left&#39;, &#39;-1200px&#39;); 
    jQuery(form).appendTo(&#39;body&#39;); 
    return form; 
  }, 
  ajaxFileUpload: function(s) { 
    // TODO introduce global settings, allowing the client to modify them for all requests, not only timeout  
    s = jQuery.extend({}, jQuery.ajaxSettings, s); 
    var id = s.fileElementId; 
    var form = jQuery.createUploadForm(id, s.fileElementId); 
    var io = jQuery.createUploadIframe(id, s.secureuri); 
    var frameId = &#39;jUploadFrame&#39; + id; 
    var formId = &#39;jUploadForm&#39; + id; 
    if( s.global && ! jQuery.active++ ) 
    { 
      // Watch for a new set of requests 
      jQuery.event.trigger( "ajaxStart" ); 
    } 
    var requestDone = false; 
    // Create the request object 
    var xml = {}; 
    if( s.global ) 
    { 
      jQuery.event.trigger("ajaxSend", [xml, s]); 
    } 
    var uploadCallback = function(isTimeout) 
    { 
      // Wait for a response to come back 
      var io = document.getElementById(frameId); 
      try 
      { 
        if(io.contentWindow) 
        { 
          xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; 
          xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; 
        }else if(io.contentDocument) 
        { 
          xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null; 
          xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document; 
        } 
      }catch(e) 
      { 
        jQuery.handleError(s, xml, null, e); 
      } 
      if( xml || isTimeout == "timeout") 
      { 
        requestDone = true; 
        var status; 
        try { 
          status = isTimeout != "timeout" ? "success" : "error"; 
          // Make sure that the request was successful or notmodified 
          if( status != "error" ) 
          { 
            // process the data (runs the xml through httpData regardless of callback) 
            var data = jQuery.uploadHttpData( xml, s.dataType ); 
            if( s.success ) 
            { 
              // ifa local callback was specified, fire it and pass it the data 
              s.success( data, status ); 
            }; 
            if( s.global ) 
            { 
              // Fire the global callback 
              jQuery.event.trigger( "ajaxSuccess", [xml, s] ); 
            }; 
          } else 
          { 
            jQuery.handleError(s, xml, status); 
          } 
        } catch(e) 
        { 
          status = "error"; 
          jQuery.handleError(s, xml, status, e); 
        }; 
        if( s.global ) 
        { 
          // The request was completed 
          jQuery.event.trigger( "ajaxComplete", [xml, s] ); 
        }; 
        // Handle the global AJAX counter 
        if(s.global && ! --jQuery.active) 
        { 
          jQuery.event.trigger("ajaxStop"); 
        }; 
        if(s.complete) 
        { 
          s.complete(xml, status); 
        } ; 
        jQuery(io).unbind(); 
        setTimeout(function() 
        { try 
        { 
          jQuery(io).remove(); 
          jQuery(form).remove(); 
        } catch(e) 
        { 
          jQuery.handleError(s, xml, null, e); 
        } 
        }, 100); 
        xml = null; 
      }; 
    } 
    // Timeout checker 
    if( s.timeout > 0 ) 
    { 
      setTimeout(function(){ 
        if( !requestDone ) 
        { 
          // Check to see ifthe request is still happening 
          uploadCallback( "timeout" ); 
        } 
      }, s.timeout); 
    } 
    try 
    { 
      var form = jQuery(&#39;#&#39; + formId); 
      jQuery(form).attr(&#39;action&#39;, s.url); 
      jQuery(form).attr(&#39;method&#39;, &#39;POST&#39;); 
      jQuery(form).attr(&#39;target&#39;, frameId); 
      if(form.encoding) 
      { 
        form.encoding = &#39;multipart/form-data&#39;; 
      } 
      else 
      { 
        form.enctype = &#39;multipart/form-data&#39;; 
      } 
      jQuery(form).submit(); 
    } catch(e) 
    { 
      jQuery.handleError(s, xml, null, e); 
    } 
    if(window.attachEvent){ 
      document.getElementById(frameId).attachEvent(&#39;onload&#39;, uploadCallback); 
    } 
    else{ 
      document.getElementById(frameId).addEventListener(&#39;load&#39;, uploadCallback, false); 
    } 
    return {abort: function () {}}; 
  }, 
  uploadHttpData: function( r, type ) { 
    var data = !type; 
    data = type == "xml" || data ? r.responseXML : r.responseText; 
    // ifthe type is "script", eval it in global context 
    if( type == "script" ) 
    { 
      jQuery.globalEval( data ); 
    } 
    // Get the JavaScript object, ifJSON is used. 
    if( type == "json" ) 
    { 
      eval( "data = " + data ); 
    } 
    // evaluate scripts within html 
    if( type == "html" ) 
    { 
      jQuery("<p>").html(data).evalScripts(); 
    } 
    return data; 
  }, 
  handleError: function( s, xhr, status, e )   { 
    // If a local callback was specified, fire it  
    if ( s.error ) { 
      s.error.call( s.context || s, xhr, status, e ); 
    } 
    // Fire the global callback 
    if ( s.global ) { 
      (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] ); 
    } 
  } 
});


登录后复制


(2)之后调用ajaxfileupload.js库,编写图片上传脚本,这里命名为ajaxfileuplaod_implement.js


<p></p><pre name="code" class="javascript">function fileUpload() {  
  var inputObject = $("#fileImage").get(0); 
  if(inputObject.value == "") 
  { 
    alert("清先选择需要上传的图片"); 
    return false; 
  } 
  $.ajaxFileUpload({  
    url: &#39;/PicSubmit/pic&#39;, //服务器端请求地址  
    secureuri: false, //是否需要安全协议,一般设置为false  
    type: &#39;post&#39;, 
    fileElementId: &#39;fileImage&#39;, //文件上传域的ID  
    dataType: &#39;text&#39;, //返回值类型 一般设置为json  
    enctype:&#39;multipart/form-data&#39;,//注意一定要有该参数  
    success: function (data, status) //服务器成功响应处理函数  
    {  
      data=decodeURI(data);//服务器端使用urlencode将中文字符编码,所以这里需要解码。这样做的目的是防止中文乱码 
      var address = JSON.parse(data); 
      for(var i=0;i<address.length;i++){ 
        ajaxfile_onSuccess(address[i]); //这里的success回调函数可以自己定义,但是有一点需要注意,就是需要把服务器返回来的图片存储路径写入
<span style="white-space:pre">              </span>//hiden标签的value值中,方法见下面的writeHide函数 
      } 
    },  
    complete: function(xmlHttpRequest)  
    {<span style="white-space:pre"> </span>//这里将html中的文件上传标签替换为新的标签,是应为我在开发过程中发现,当ajax执行一次上传操作之后,再使用file标签选择文件时,标签没有反应,
<span style="white-space:pre">   </span>//所以暂时使用了这种方法。 
      inputObject.replaceWith(&#39;<input type="file" id="fileImage" name="fileImage" />&#39;); 
    }, 
    error: function (data, status, e)//服务器响应失败处理函数 
    {  
      //alert("无法连接到服务器"); 
    }  
  })  
}
function writeHide(data){ 
<span style="white-space:pre"> </span>if($("#addressid").get(0).value == "") 
<span style="white-space:pre"> </span>{ 
<span style="white-space:pre">   </span>$("#addressid").get(0).value = data.newName; 
<span style="white-space:pre"> </span>} 
<span style="white-space:pre"> </span>else 
<span style="white-space:pre"> </span>{ 
<span style="white-space:pre">   </span>$("#addressid").get(0).value = $("#addressid").get(0).value+","+data.newName; 
<span style="white-space:pre"> </span>} 
} 

3 spring.

完成上面两个部分之后,前台的主要工作基本就结束了。我后台使用了spring框架。

首先是springMVC的配置文件:viewspace-servlet.xml

<?xml version="1.0" encoding="UTF-8" ?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.1.xsd"> 
  <!-- 静态资源 --> 
  <mvc:resources mapping="/js/**" location="/js/" /> 
  <mvc:resources mapping="/css/**" location="/css/" /> 
  <mvc:resources mapping="/image/**" location="/image/" /> 
  <!-- 扫描web包,应用Spring的注解 --> 
  <context:component-scan base-package="web"/> 
  <bean id="defaultAnnotationHandlerMapping" 
     class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" /> 
  <bean id="annotationMethodHandlerAdapter" 
     class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" /> 
  <!-- 配置视图解析器,将ModelAndView及字符串解析为具体的页面 --> 
  <bean 
      class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
      p:viewClass="org.springframework.web.servlet.view.JstlView" 
      p:prefix="/WEB-INF/jsp/" 
      p:suffix=".jsp"/>  
  <!-- 使springMVC支持图片上传 -->  
  <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
      <!-- 最大上传尺寸1MB --> 
      <property name="maxUploadSize" value="10485760"/> 
      <!-- 默认编码 --> 
      <property name="defaultEncoding" value="UTF-8" /> 
      <!-- 上传文件的解析 --> 
      <property name="resolveLazily" value="true" /> 
  </bean> 
  <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException --> 
   <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 --> 
   <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" > 
     <property name="exceptionMappings"> 
       <props> 
         <!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_toobig.jsp页面 --> 
         <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop> 
      </props> 
    </property> 
   </bean> 
</beans>
其中,类“org.springframework.web.multipart.commons.CommonsMultipartResolver”的配置是必须的,否则后台无法收到前台传来的文件。


为了防止文件名中的中文字符传输出现问题,在web.xml中做如下配置:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> 
 <context-param> 
  <param-name>contextConfigLocation</param-name> 
  <param-value>classpath:applicationContext.xml</param-value> 
 </context-param> 
 <listener> 
  <listener-class> 
      org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
 </listener> 
 <servlet> 
  <servlet-name>viewspace</servlet-name> 
  <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
    </servlet-class> 
 </servlet> 
 <servlet-mapping> 
  <servlet-name>viewspace</servlet-name> 
  <url-pattern>/</url-pattern> 
 </servlet-mapping> 
 <!-- 支持传输中文字符 --> 
 <filter>  
    <filter-name>characterEncodingFilter</filter-name>  
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
    <init-param>  
      <param-name>encoding</param-name>  
      <param-value>UTF-8</param-value>  
    </init-param>  
    <init-param>  
      <param-name>forceEncoding</param-name>  
      <param-value>true</param-value>  
    </init-param>  
  </filter>  
  <filter-mapping>  
    <filter-name>characterEncodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
  </filter-mapping>  
</web-app>


登录后复制


接下来是重点,在Controller中,使用如下方式接受前台穿回来的文件。


<pre name="code" class="java"> @RequestMapping(value="/pic") 
  @ResponseBody 
  public String submitPic(@RequestParam(value = "filename",required = false) MultipartFile[] fileImage,  
      HttpServletRequest request){ 
    if(fileImage == null){ 
      return "[]"; 
    } 
    return picSaveService.savePic(fileImage); 
  }

登录后复制


其中需要注意的是,如果前端html的input标签中使用了multiple属性,则表示标签支持上传多个图片,则controller的参数列表中,文件的类型使用MultipartFile[],反之,如果没有使用multiple属性,表示上传的是一张图片,则controller使用MultipartFile类型接收。


<p><br> 
</p><p>文件接收完成后,就可以对文件进行存储了,方法有很多,我这里举一个例子如下:</p> 
<p></p><pre name="code" class="java">  public String savePic(MultipartFile[] fileImage){ 
    //为图片改名 
    String oldName = ""; 
    String newName = ""; 
    String extension = ""; 
    //图片按照上传时间命名 
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); 
    //存储每张图片的信息 
    List<PicConfirmData> resultList = new ArrayList<PicConfirmData>(); 
    //获取配置文件中图片的存储路径 
    String path = Parameters.getInstance().getDatabaseProps().getProperty("pic_save_dir"); 
    //依次将图片存储到path路径下 
    for(int i=0;i<fileImage.length;i++){ 
      System.out.println(fileImage[i].getOriginalFilename()); 
      oldName = fileImage[i].getOriginalFilename();     
      extension = oldName.substring(oldName.lastIndexOf(".")); 
      newName = sdf.format(new Date())+extension; 
      File target = new File(path,newName); 
      if(!target.exists()){ 
        target.mkdirs(); 
      } 
      try { 
          fileImage[i].transferTo(target); 
        } catch (IllegalStateException e) { 
          e.printStackTrace(); 
        } catch (IOException e) { 
          e.printStackTrace(); 
        } 
      //记录图片存储信息 
      PicConfirmData pic = null; 
      try { 
        //只存名称,路径已知,从而节省数据库空间 
        //pic = new PicConfirmData(URLEncoder.encode(oldName, "utf-8"), path+newName); 
        pic = new PicConfirmData(1,URLEncoder.encode(oldName, "utf-8"), newName); 
        resultList.add(pic); 
      } catch (UnsupportedEncodingException e) { 
        e.printStackTrace(); 
      } 
    } 
    return ToolJson.getJsonFromPicConfirmData(resultList); 
  }
这里将接收到的图片的原始名称以及修改后存储使用的名称返回给前台,原始名称用于在前台页面输出“存储成功”的提示信息,修改后的名称用于给hiden标签复制,hiden标签的内容会在之后随表单中其他信息一起提交到服务端,通过hiden标签,我们就可以知道与表单关联的图片被存储在什么地方。

最后,图片上传完成后还需要提交表单,这里使用SpringMVC实现一个表单接收功能。这里名为address的参数,存储的就是图片的存储路径。

  @RequestMapping(value="/form") 
  public String submitForm(HttpServletRequest request){ 
    String sid = request.getParameter("name"); 
    String address = request.getParameter("address"); 
     
    if(sid != null && submiter != null && faultTime != null && message != null && address != null){ 
      if(formDataSaveService.saveForm(sid, submiter, message, address, faultTime)){ 
        return "ac"; 
      } 
    } 
    return "error"; 
  }

登录后复制


方法二 前台切割上传(留着后面补充)


<p><br> 
</p> 
<link rel="stylesheet" href="http://static.jb51.net/public/res-min/markdown_views.css?v=1.0"> 
           
登录后复制


以上所述是小编给大家介绍的Ajax配合Spring实现文件上传功能代码,希望对大家有所帮助!!、

相关推荐:

实例分析ajax和php实现无刷新验证手机号

全面总结基于jQuery中ajax的相关方法

Ajax应该如何使用

以上是Ajax配合Spring实现文件上传功能代码的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

出现0x80004005错误代码怎么办 小编教你0x80004005错误代码解决方法 出现0x80004005错误代码怎么办 小编教你0x80004005错误代码解决方法 Mar 21, 2024 pm 09:17 PM

在电脑中删除或解压缩文件夹,时有时候会弹出提示对话框“错误0x80004005:未指定错误”,如果遇到这中情况应该怎么解决呢?提示错误代码0x80004005的原因其实有很多,但大部分因为病毒导致,我们可以重新注册dll来解决问题,下面,小编给大伙讲解0x80004005错误代码处理经验。有用户在使用电脑时出现错误代码0X80004005的提示,0x80004005错误主要是由于计算机没有正确注册某些动态链接库文件,或者计算机与Internet之间存在不允许的HTTPS连接防火墙所引起。那么如何

利用Spring Boot以及Spring AI构建生成式人工智能应用 利用Spring Boot以及Spring AI构建生成式人工智能应用 Apr 28, 2024 am 11:46 AM

Spring+AI作为行业领导者,通过其强大、灵活的API和先进的功能,为各种行业提供了领先性的解决方案。在本专题中,我们将深入探讨Spring+AI在各领域的应用示例,每个案例都将展示Spring+AI如何满足特定需求,实现目标,并将这些LESSONSLEARNED扩展到更广泛的应用。希望这个专题能对你有所启发,更深入地理解和利用Spring+AI的无限可能。Spring框架在软件开发领域已经有超过20年的历史,自SpringBoot1.0版本发布以来已有10年。现在,无人会质疑,Spring

夸克网盘的文件怎么转移到百度网盘? 夸克网盘的文件怎么转移到百度网盘? Mar 14, 2024 pm 02:07 PM

  夸克网盘和百度网盘都是现在最常用的储存文件的网盘软件,如果想要将夸克网盘内的文件保存到百度网盘,要怎么操作呢?本期小编整理了夸克网盘电脑端的文件转移到百度网盘的教程步骤,一起来看看是怎么操作吧。  夸克网盘的文件怎么保存到百度网盘?要将夸克网盘的文件转移到百度网盘,首先需在夸克网盘下载所需文件,然后在百度网盘客户端中选择目标文件夹并打开。接着,将夸克网盘中下载的文件拖放到百度网盘客户端打开的文件夹中,或者使用上传功能将文件添加至百度网盘。确保上传完成后在百度网盘中查看文件是否成功转移。这样就

hiberfil.sys是什么文件?hiberfil.sys可以删除吗? hiberfil.sys是什么文件?hiberfil.sys可以删除吗? Mar 15, 2024 am 09:49 AM

  最近有很多网友问小编,hiberfil.sys是什么文件?hiberfil.sys占用了大量的C盘空间可以删除吗?小编可以告诉大家hiberfil.sys文件是可以删除的。下面就来看看详细的内容。hiberfil.sys是Windows系统中的一个隐藏文件,也是系统休眠文件。通常存储在C盘根目录下,其大小与系统安装内存大小相当。这个文件在计算机休眠时被使用,其中包含了当前系统的内存数据,以便在恢复时快速恢复到之前的状态。由于其大小与内存容量相等,因此它可能会占用较大的硬盘空间。  hiber

PHP 与 Ajax:构建一个自动完成建议引擎 PHP 与 Ajax:构建一个自动完成建议引擎 Jun 02, 2024 pm 08:39 PM

使用PHP和Ajax构建自动完成建议引擎:服务器端脚本:处理Ajax请求并返回建议(autocomplete.php)。客户端脚本:发送Ajax请求并显示建议(autocomplete.js)。实战案例:在HTML页面中包含脚本并指定search-input元素标识符。

MySQL中.ibd文件的作用详解及相关注意事项 MySQL中.ibd文件的作用详解及相关注意事项 Mar 15, 2024 am 08:00 AM

MySQL中.ibd文件的作用详解及相关注意事项MySQL是一种流行的关系型数据库管理系统,数据库中的数据存储在不同的文件中。其中,.ibd文件是InnoDB存储引擎中的数据文件,用于存储表中的数据和索引。本文将对MySQL中.ibd文件的作用进行详细解析,并提供相关代码示例以帮助读者更好地理解。一、.ibd文件的作用:存储数据:.ibd文件是InnoDB存

Linux系统查看log日志命令详解! Linux系统查看log日志命令详解! Mar 06, 2024 pm 03:55 PM

在Linux系统中,可以使用以下命令来查看日志文件的内容:tail命令:tail命令用于显示日志文件的末尾内容。它是查看最新日志信息的常用命令。tail[选项][文件名]常用的选项包括:-n:指定要显示的行数,默认为10行。-f:实时监视文件内容,并在文件更新时自动显示新的内容。示例:tail-n20logfile.txt#显示logfile.txt文件的最后20行内容tail-flogfile.txt#实时监视logfile.txt文件的更新内容head命令:head命令用于显示日志文件的开头

创建和运行Linux'.a”文件 创建和运行Linux'.a”文件 Mar 20, 2024 pm 04:46 PM

在Linux操作系统中处理文件需要使用各种命令和技术,使开发人员能够高效地创建和执行文件、代码、程序、脚本和其他东西。在Linux环境中,扩展名为”.a”的文件作为静态库具有重要的重要性。这些库在软件开发中发挥着重要作用,允许开发人员有效地管理和共享多个程序的公共功能。对于Linux环境中的有效软件开发,了解如何创建和运行“.a”文件至关重要。本文将介绍如何全面安装和配置Linux“.a”文件,让我们一起探索Linux“.a”文件的定义、用途、结构,以及创建和执行它的方法。什么是L

See all articles