struts2 method to get the server temporary directory
- 2020-11-03 22:11:29
- OfStack
struts2 gets the temporary directory of the server (tomcat, WebLogic) for your reference, the specific content is as follows
Need to import:
import java.io.File;
import org.apache.struts2.ServletActionContext;
Methods encapsulate
// Specifies the directory of the server for temporary storage
public static final String TEMP_DIR_CONTEXT_ATTRIBUTE = "javax.servlet.context.tempdir";
/**
* Get temporary directory
* @return
*/
public static File getTempDir() {
return (File) ServletActionContext.getServletContext().getAttribute(
TEMP_DIR_CONTEXT_ATTRIBUTE);
}
Application: When uploading files, you can store the files obtained from the client in this directory. For details, please go to the upload section of servlet to realize file uploading, preview, Download and delete