When you use Smartupload for file uploads, you need to use Srevletconfig:
Writing in a servlet is, of course, easy to implement:
Private ServletConfig config;//initialization servletfinal public void init (ServletConfig config) throws servletexception{ This.config=config;}
The Init method gets to ServletConfig when the servlet is initialized.
But how do you get it in the controller? Through the small series of advice, you can inherit servletconfigaware,servletcontextaware these two interfaces to achieve:
Package Module.system.controller;import Java.io.ioexception;import Javax.servlet.servletconfig;import Javax.servlet.servletcontext;import Javax.servlet.servletexception;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Module.system.common.fileload;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.requestmethod;import Org.springframework.web.bind.annotation.responsebody;import Org.springframework.web.context.ServletConfigAware; Import org.springframework.web.context.servletcontextaware;/** * File upload download. * */@Controller @requestmapping ("/fileload") public class Fileloadcontroller implements Servletconfigaware, Servletcontextaware{private ServletContext ServletContext, @Overridepublic void Setservletcontext (ServletContext arg0) {this.servletcontext = arg0;} Private ServletConfig ServletConfig; @Overridepublic void Setservletconfig (ServletConfig arg0) {this.servletconfig = arg0;} @RequestMapping (value = "/upload.do", method = Requestmethod.post) @ResponseBody//This note indicates that the return value skips the View Processing section and writes directly to the HTTP response Body public String Upload (httpservletrequest request,httpservletresponse response) {Fileload fileload = new Fileload (); try {fileload.upload (request, Response,servletconfig),} catch (Servletexception e) {e.printstacktrace ();} catch ( IOException e) {e.printstacktrace ();} Return "";}}
Inside this upload method is another written method that will be introduced in the next article. By doing so, we can get servletconfig.
Get ServletConfig in the controller of spring MVC