Struts(二十六):文件上传
表单的准备
想要使用html表单上传一个或多个文件
1、须把html表单的enctype属性设置为multipart/form-data
2、须把html表单的method属性设置为post
3、须添加<input type="file">字段
Struts2的进行单文件上传需要操作步骤:
1、需要引入struts2需要的包,struts2上传是需要使用fileUpload拦截器实现的,而实际上上传文件是使用Commons FileUpload组建,所以需要导入commons-fileupload-1.3.2.jar、commons-io-2.2.jar包。
2、定制表单index.jsp
<s:form action="testUpload" method="post" enctype="multipart/form-data"
theme="simple">
File:<s:file name="myFile"></s:file>
File Description:<s:textfield name="desc"></s:textfield>
<s:submit value="Submit"></s:submit>
</s:form>
3、基本的文件上传设置:直接在action类中定义如下三个属性,并实现getter和setter
private File myFile;
private String myFileContentType;
private String myFileFileName; public File getMyFile() {
return myFile;
} public void setMyFile(File myFile) {
this.myFile = myFile;
} public String getMyFileContentType() {
return myFileContentType;
} public void setMyFileContentType(String myFileContentType) {
this.myFileContentType = myFileContentType;
} public String getMyFileFileName() {
return myFileFileName;
} public void setMyFileFileName(String myFileFileName) {
this.myFileFileName = myFileFileName;
}
备注:当查看fileUpload拦截器源码
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/ package org.apache.struts2.interceptor; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.LocaleProvider;
import com.opensymphony.xwork2.TextProvider;
import com.opensymphony.xwork2.TextProviderFactory;
import com.opensymphony.xwork2.ValidationAware;
import com.opensymphony.xwork2.inject.Container;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.TextParseUtil;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
import org.apache.struts2.util.ContentTypeMatcher; import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set; /**
* <!-- START SNIPPET: description -->
* <p/>
* Interceptor that is based off of {@link MultiPartRequestWrapper}, which is automatically applied for any request that
* includes a file. It adds the following parameters, where [File Name] is the name given to the file uploaded by the
* HTML form:
* <p/>
* <ul>
* <p/>
* <li>[File Name] : File - the actual File</li>
* <p/>
* <li>[File Name]ContentType : String - the content type of the file</li>
* <p/>
* <li>[File Name]FileName : String - the actual name of the file uploaded (not the HTML name)</li>
* <p/>
* </ul>
* <p/>
* <p/> You can get access to these files by merely providing setters in your action that correspond to any of the three
* patterns above, such as setDocument(File document), setDocumentContentType(String contentType), etc.
* <br/>See the example code section.
* <p/>
* <p/> This interceptor will add several field errors, assuming that the action implements {@link ValidationAware}.
* These error messages are based on several i18n values stored in struts-messages.properties, a default i18n file
* processed for all i18n requests. You can override the text of these messages by providing text for the following
* keys:
* <p/>
* <ul>
* <p/>
* <li>struts.messages.error.uploading - a general error that occurs when the file could not be uploaded</li>
* <p/>
* <li>struts.messages.error.file.too.large - occurs when the uploaded file is too large</li>
* <p/>
* <li>struts.messages.error.content.type.not.allowed - occurs when the uploaded file does not match the expected
* content types specified</li>
* <p/>
* <li>struts.messages.error.file.extension.not.allowed - occurs when the uploaded file does not match the expected
* file extensions specified</li>
* <p/>
* </ul>
* <p/>
* <!-- END SNIPPET: description -->
* <p/>
* <p/> <u>Interceptor parameters:</u>
* <p/>
* <!-- START SNIPPET: parameters -->
* <p/>
* <ul>
* <p/>
* <li>maximumSize (optional) - the maximum size (in bytes) that the interceptor will allow a file reference to be set
* on the action. Note, this is <b>not</b> related to the various properties found in struts.properties.
* Default to approximately 2MB.</li>
* <p/>
* <li>allowedTypes (optional) - a comma separated list of content types (ie: text/html) that the interceptor will allow
* a file reference to be set on the action. If none is specified allow all types to be uploaded.</li>
* <p/>
* <li>allowedExtensions (optional) - a comma separated list of file extensions (ie: .html) that the interceptor will allow
* a file reference to be set on the action. If none is specified allow all extensions to be uploaded.</li>
* </ul>
* <p/>
* <p/>
* <!-- END SNIPPET: parameters -->
* <p/>
* <p/> <u>Extending the interceptor:</u>
* <p/>
* <p/>
* <p/>
* <!-- START SNIPPET: extending -->
* <p/>
* You can extend this interceptor and override the acceptFile method to provide more control over which files
* are supported and which are not.
* <p/>
* <!-- END SNIPPET: extending -->
* <p/>
* <p/> <u>Example code:</u>
* <p/>
* <pre>
* <!-- START SNIPPET: example-configuration -->
* <action name="doUpload" class="com.example.UploadAction">
* <interceptor-ref name="fileUpload"/>
* <interceptor-ref name="basicStack"/>
* <result name="success">good_result.jsp</result>
* </action>
* <!-- END SNIPPET: example-configuration -->
* </pre>
* <p/>
* <!-- START SNIPPET: multipart-note -->
* <p/>
* You must set the encoding to <code>multipart/form-data</code> in the form where the user selects the file to upload.
* <p/>
* <!-- END SNIPPET: multipart-note -->
* <p/>
* <pre>
* <!-- START SNIPPET: example-form -->
* <s:form action="doUpload" method="post" enctype="multipart/form-data">
* <s:file name="upload" label="File"/>
* <s:submit/>
* </s:form>
* <!-- END SNIPPET: example-form -->
* </pre>
* <p/>
* And then in your action code you'll have access to the File object if you provide setters according to the
* naming convention documented in the start.
* <p/>
* <pre>
* <!-- START SNIPPET: example-action -->
* package com.example;
*
* import java.io.File;
* import com.opensymphony.xwork2.ActionSupport;
*
* public UploadAction extends ActionSupport {
* private File file;
* private String contentType;
* private String filename;
*
* public void setUpload(File file) {
* this.file = file;
* }
*
* public void setUploadContentType(String contentType) {
* this.contentType = contentType;
* }
*
* public void setUploadFileName(String filename) {
* this.filename = filename;
* }
*
* public String execute() {
* //...
* return SUCCESS;
* }
* }
* <!-- END SNIPPET: example-action -->
* </pre>
*/
public class FileUploadInterceptor extends AbstractInterceptor { private static final long serialVersionUID = -4764627478894962478L; protected static final Logger LOG = LoggerFactory.getLogger(FileUploadInterceptor.class); protected Long maximumSize;
protected Set<String> allowedTypesSet = Collections.emptySet();
protected Set<String> allowedExtensionsSet = Collections.emptySet(); private ContentTypeMatcher matcher;
private Container container; @Inject
public void setMatcher(ContentTypeMatcher matcher) {
this.matcher = matcher;
} @Inject
public void setContainer(Container container) {
this.container = container;
} /**
* Sets the allowed extensions
*
* @param allowedExtensions A comma-delimited list of extensions
*/
public void setAllowedExtensions(String allowedExtensions) {
allowedExtensionsSet = TextParseUtil.commaDelimitedStringToSet(allowedExtensions);
} /**
* Sets the allowed mimetypes
*
* @param allowedTypes A comma-delimited list of types
*/
public void setAllowedTypes(String allowedTypes) {
allowedTypesSet = TextParseUtil.commaDelimitedStringToSet(allowedTypes);
} /**
* Sets the maximum size of an uploaded file
*
* @param maximumSize The maximum size in bytes
*/
public void setMaximumSize(Long maximumSize) {
this.maximumSize = maximumSize;
} /* (non-Javadoc)
* @see com.opensymphony.xwork2.interceptor.Interceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
*/ public String intercept(ActionInvocation invocation) throws Exception {
ActionContext ac = invocation.getInvocationContext(); HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST); if (!(request instanceof MultiPartRequestWrapper)) {
if (LOG.isDebugEnabled()) {
ActionProxy proxy = invocation.getProxy();
LOG.debug(getTextMessage("struts.messages.bypass.request", new String[]{proxy.getNamespace(), proxy.getActionName()}));
} return invocation.invoke();
} ValidationAware validation = null; Object action = invocation.getAction(); if (action instanceof ValidationAware) {
validation = (ValidationAware) action;
} MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request; if (multiWrapper.hasErrors()) {
for (String error : multiWrapper.getErrors()) {
if (validation != null) {
validation.addActionError(error);
}
}
} // bind allowed Files
Enumeration fileParameterNames = multiWrapper.getFileParameterNames();
while (fileParameterNames != null && fileParameterNames.hasMoreElements()) {
// get the value of this input tag
String inputName = (String) fileParameterNames.nextElement(); // get the content type
String[] contentType = multiWrapper.getContentTypes(inputName); if (isNonEmpty(contentType)) {
// get the name of the file from the input tag
String[] fileName = multiWrapper.getFileNames(inputName); if (isNonEmpty(fileName)) {
// get a File object for the uploaded File
File[] files = multiWrapper.getFiles(inputName);
if (files != null && files.length > 0) {
List<File> acceptedFiles = new ArrayList<File>(files.length);
List<String> acceptedContentTypes = new ArrayList<String>(files.length);
List<String> acceptedFileNames = new ArrayList<String>(files.length);
String contentTypeName = inputName + "ContentType";
String fileNameName = inputName + "FileName"; for (int index = 0; index < files.length; index++) {
if (acceptFile(action, files[index], fileName[index], contentType[index], inputName, validation)) {
acceptedFiles.add(files[index]);
acceptedContentTypes.add(contentType[index]);
acceptedFileNames.add(fileName[index]);
}
} if (!acceptedFiles.isEmpty()) {
Map<String, Object> params = ac.getParameters(); params.put(inputName, acceptedFiles.toArray(new File[acceptedFiles.size()]));
params.put(contentTypeName, acceptedContentTypes.toArray(new String[acceptedContentTypes.size()]));
params.put(fileNameName, acceptedFileNames.toArray(new String[acceptedFileNames.size()]));
}
}
} else {
if (LOG.isWarnEnabled()) {
LOG.warn(getTextMessage(action, "struts.messages.invalid.file", new String[]{inputName}));
}
}
} else {
if (LOG.isWarnEnabled()) {
LOG.warn(getTextMessage(action, "struts.messages.invalid.content.type", new String[]{inputName}));
}
}
} // invoke action
return invocation.invoke();
} /**
* Override for added functionality. Checks if the proposed file is acceptable based on contentType and size.
*
* @param action - uploading action for message retrieval.
* @param file - proposed upload file.
* @param contentType - contentType of the file.
* @param inputName - inputName of the file.
* @param validation - Non-null ValidationAware if the action implements ValidationAware, allowing for better
* logging.
* @return true if the proposed file is acceptable by contentType and size.
*/
protected boolean acceptFile(Object action, File file, String filename, String contentType, String inputName, ValidationAware validation) {
boolean fileIsAcceptable = false; // If it's null the upload failed
if (file == null) {
String errMsg = getTextMessage(action, "struts.messages.error.uploading", new String[]{inputName});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
} if (LOG.isWarnEnabled()) {
LOG.warn(errMsg);
}
} else if (maximumSize != null && maximumSize < file.length()) {
String errMsg = getTextMessage(action, "struts.messages.error.file.too.large", new String[]{inputName, filename, file.getName(), "" + file.length(), getMaximumSizeStr(action)});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
} if (LOG.isWarnEnabled()) {
LOG.warn(errMsg);
}
} else if ((!allowedTypesSet.isEmpty()) && (!containsItem(allowedTypesSet, contentType))) {
String errMsg = getTextMessage(action, "struts.messages.error.content.type.not.allowed", new String[]{inputName, filename, file.getName(), contentType});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
} if (LOG.isWarnEnabled()) {
LOG.warn(errMsg);
}
} else if ((!allowedExtensionsSet.isEmpty()) && (!hasAllowedExtension(allowedExtensionsSet, filename))) {
String errMsg = getTextMessage(action, "struts.messages.error.file.extension.not.allowed", new String[]{inputName, filename, file.getName(), contentType});
if (validation != null) {
validation.addFieldError(inputName, errMsg);
} if (LOG.isWarnEnabled()) {
LOG.warn(errMsg);
}
} else {
fileIsAcceptable = true;
} return fileIsAcceptable;
} private String getMaximumSizeStr(Object action) {
return NumberFormat.getNumberInstance(getLocaleProvider(action).getLocale()).format(maximumSize);
} /**
* @param extensionCollection - Collection of extensions (all lowercase).
* @param filename - filename to check.
* @return true if the filename has an allowed extension, false otherwise.
*/
private boolean hasAllowedExtension(Collection<String> extensionCollection, String filename) {
if (filename == null) {
return false;
} String lowercaseFilename = filename.toLowerCase();
for (String extension : extensionCollection) {
if (lowercaseFilename.endsWith(extension)) {
return true;
}
} return false;
} /**
* @param itemCollection - Collection of string items (all lowercase).
* @param item - Item to search for.
* @return true if itemCollection contains the item, false otherwise.
*/
private boolean containsItem(Collection<String> itemCollection, String item) {
for (String pattern : itemCollection)
if (matchesWildcard(pattern, item))
return true;
return false;
} private boolean matchesWildcard(String pattern, String text) {
Object o = matcher.compilePattern(pattern);
return matcher.match(new HashMap<String, String>(), text, o);
} private boolean isNonEmpty(Object[] objArray) {
boolean result = false;
for (int index = 0; index < objArray.length && !result; index++) {
if (objArray[index] != null) {
result = true;
}
}
return result;
} protected String getTextMessage(String messageKey, String[] args) {
return getTextMessage(this, messageKey, args);
} protected String getTextMessage(Object action, String messageKey, String[] args) {
if (action instanceof TextProvider) {
return ((TextProvider) action).getText(messageKey, args);
}
return getTextProvider(action).getText(messageKey, args);
} private TextProvider getTextProvider(Object action) {
TextProviderFactory tpf = new TextProviderFactory();
if (container != null) {
container.inject(tpf);
}
LocaleProvider localeProvider = getLocaleProvider(action);
return tpf.createInstance(action.getClass(), localeProvider);
} private LocaleProvider getLocaleProvider(Object action) {
LocaleProvider localeProvider;
if (action instanceof LocaleProvider) {
localeProvider = (LocaleProvider) action;
} else {
localeProvider = container.getInstance(LocaleProvider.class);
}
return localeProvider;
} }
时,发现doc文件中备注信息:
org.apache.struts2.interceptor.FileUploadInterceptor
Interceptor that is based off of MultiPartRequestWrapper, which is automatically applied for any request that includes a file.
It adds the following parameters, where [File Name] is the name given to the file uploaded by the HTML form:
•[File Name] : File - the actual File
•[File Name]ContentType : String - the content type of the file
•[File Name]FileName : String - the actual name of the file uploaded (not the HTML name)
4、使用io进行文件上传,需要在struts.xml定义action,并在对应的action中实现io上传
<action name="testUpload" class="com.dx.struts2.actions.UploadAction">
<result>/success.jsp</result>
<result name="input">/index.jsp</result>
</action>
UploadAction.java(需要在WebContent下创建文件夹files)
package com.dx.struts2.actions; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import javax.servlet.ServletContext; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class UploadAction extends ActionSupport {
private static final long serialVersionUID = 1L; private File myFile;
private String myFileContentType;
private String myFileFileName; public File getMyFile() {
return myFile;
} public void setMyFile(File myFile) {
this.myFile = myFile;
} public String getMyFileContentType() {
return myFileContentType;
} public void setMyFileContentType(String myFileContentType) {
this.myFileContentType = myFileContentType;
} public String getMyFileFileName() {
return myFileFileName;
} public void setMyFileFileName(String myFileFileName) {
this.myFileFileName = myFileFileName;
} @Override
public String execute() throws Exception {
System.out.println(myFile);
System.out.println(myFileContentType);
System.out.println(myFileFileName);
System.out.println("execute..."); ServletContext servletContext = ServletActionContext.getServletContext();
String savePath = servletContext.getRealPath("/files/" + myFileFileName);
System.out.println(savePath); FileOutputStream out = new FileOutputStream(savePath);
FileInputStream in = new FileInputStream(myFile); byte[] bytes = new byte[1024];
int length = 0; while ((length = in.read(bytes)) != -1) {
out.write(bytes, 0, length);
} out.close();
in.close(); return super.execute();
}
}
Struts2的进行多文件上传需要操作步骤:
1、form表单修改:(需要注意的是页面其他属性File Description name需要有下标,否则无法回填)
<s:debug></s:debug>
<s:form action="testUpload" method="post" enctype="multipart/form-data"
theme="simple">
File:<s:file name="myFile"></s:file>
File Description:<s:textfield name="desc[0]"></s:textfield>
<br><br>
File:<s:file name="myFile"></s:file>
File Description:<s:textfield name="desc[1]"></s:textfield>
<s:submit value="Submit"></s:submit>
</s:form>
2、上传文件属性文件修改为List
package com.dx.struts2.actions; import java.io.File;
import java.util.List; import com.opensymphony.xwork2.ActionSupport; public class UploadAction extends ActionSupport {
private static final long serialVersionUID = 1L; private List<File> myFile;
private List<String> myFileContentType;
private List<String> myFileFileName; private List<String> desc; public List<File> getMyFile() {
return myFile;
}
public void setMyFile(List<File> myFile) {
this.myFile = myFile;
}
public List<String> getMyFileContentType() {
return myFileContentType;
}
public void setMyFileContentType(List<String> myFileContentType) {
this.myFileContentType = myFileContentType;
}
public List<String> getMyFileFileName() {
return myFileFileName;
}
public void setMyFileFileName(List<String> myFileFileName) {
this.myFileFileName = myFileFileName;
}
public List<String> getDesc() {
return desc;
}
public void setDesc(List<String> desc) {
this.desc = desc;
} @Override
public String execute() throws Exception {
System.out.println(myFile);
System.out.println(myFileContentType);
System.out.println(myFileFileName);
System.out.println(desc); System.out.println("execute..."); return super.execute();
}
}
3、提交页面后,后台打印信息:
[D:\Work\Java\apache-tomcat-7.0.-windows-x64\apache-tomcat-7.0.\work\Catalina\localhost\Struts_07FileUpload\upload_c2e431f2_8b1a_4aa7_a1d6_ae448d1dddb1_00000004.tmp,
D:\Work\Java\apache-tomcat-7.0.-windows-x64\apache-tomcat-7.0.\work\Catalina\localhost\Struts_07FileUpload\upload_c2e431f2_8b1a_4aa7_a1d6_ae448d1dddb1_00000006.tmp]
[image/jpeg, image/jpeg]
[.jpg, .jpg]
[a, b]
execute...
如何对上传文件的错误信息进行国际化
当我们查看fileUpload拦截器源代码时,会发现其doc文件中写着以下信息:
This interceptor will add several field errors, assuming that the action implements ValidationAware.
These error messages are based on several i18n values stored in struts-messages.properties, a default i18n file processed for all i18n requests.
You can override the text of these messages by providing text for the following keys: •struts.messages.error.uploading - a general error that occurs when the file could not be uploaded
•struts.messages.error.file.too.large - occurs when the uploaded file is too large
•struts.messages.error.content.type.not.allowed - occurs when the uploaded file does not match the expected content types specified
•struts.messages.error.file.extension.not.allowed - occurs when the uploaded file does not match the expected file extensions specified
因此,可以在src下创建i18n.properties文件,并在文件内容定义:
struts.messages.error.uploading=""
struts.messages.error.file.too.large=""
struts.messages.error.content.type.not.allowed=""
struts.messages.error.file.extension.not.allowed=""
在struts.xml中定义国际化设置
<constant name="struts.custom.i18n.resources" value="i18n"></constant>
还可以参考struts-core.jar下的org.apache.struts2包下的struts-messages.properties文件中的message信息:
struts.messages.error.uploading=Error uploading: {0}
struts.messages.error.file.too.large=File {0} is too large to be uploaded. Maximum allowed size is {4} bytes!
struts.messages.error.content.type.not.allowed=Content-Type not allowed: {0} "{1}" "{2}" {3}
struts.messages.error.file.extension.not.allowed=File extension not allowed: {0} "{1}" "{2}" {3}
如何对上传文件限定,大小、文件内容类型、扩展名以及总文件大小显示修改
当我们查看fileUpload拦截器源代码时,会发现其doc文件中写着以下信息:
Interceptor parameters:
•maximumSize (optional) - the maximum size (in bytes) that the interceptor will allow a file reference to be set on the action. Note, this is not related to the various properties found in struts.properties. Default to approximately 2MB.
•allowedTypes (optional) - a comma separated list of content types (ie: text/html) that the interceptor will allow a file reference to be set on the action. If none is specified allow all types to be uploaded.
•allowedExtensions (optional) - a comma separated list of file extensions (ie: .html) that the interceptor will allow a file reference to be set on the action. If none is specified allow all extensions to be uploaded. Extending the interceptor:
You can extend this interceptor and override the acceptFile method to provide more control over which files are supported and which are not. Example code:
<action name="doUpload" class="com.example.UploadAction">
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="basicStack"/>
<result name="success">good_result.jsp</result>
</action>
我们可以通过重写fileUpload拦截器的maximumSize 、allowedTypes 、allowedExtensions 三个字段来设置参数,具体操作修改struts.xml
<interceptors>
<interceptor-stack name="myInterceptorStack">
<interceptor-ref name="defaultStack">
<param name="fileUpload.maximumSize">2000</param>
<param name="fileUpload.allowedTypes">text/html,text/xml</param>
<param name="fileUpload.allowedExtensions">html,dtd,xml</param>
</interceptor-ref>
</interceptor-stack>
</interceptors> <default-interceptor-ref name="myInterceptorStack"></default-interceptor-ref>
重写总文件大小限定,总文件大小设置在struts-core.jar下的org.apache.struts2包下的default.properties文件中:
struts.multipart.maxSize=2097152
可以通过在struts.xml中定义常量来覆盖:
<constant name="struts.multipart.maxSize" value="20971520"></constant>
Struts(二十六):文件上传的更多相关文章
- 使用Typescript重构axios(二十五)——文件上传下载进度监控
0. 系列文章 1.使用Typescript重构axios(一)--写在最前面 2.使用Typescript重构axios(二)--项目起手,跑通流程 3.使用Typescript重构axios(三) ...
- JavaWeb学习 (二十八)————文件上传和下载
在Web应用系统开发中,文件上传和下载功能是非常常用的功能,今天来讲一下JavaWeb中的文件上传和下载功能的实现. 对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用 ...
- struts2(六) 文件上传和下载
前面对文件下载提过一点点,这里正好要讲文件上传,就放在一起在说一遍. --WH 一.单文件上传 在没学struts2之前,我们要写文件上传,非常麻烦,需要手动一步步去获取表单中的各种属性,然后在进行相 ...
- JavaWeb 后端 <十四> 文件上传下载
1.文件上传与下载 案例: 注册表单/保存商品等相关模块! --à 注册选择头像 / 商品图片 (数据库:存储图片路径 / 图片保存到服务器中指定的目录) 1.1 文件上传 文件上传,要点: 前台: ...
- 转:在Struts 2中实现文件上传
(本文转自:http://www.blogjava.net/max/archive/2007/03/21/105124.html) 前一阵子有些朋友在电子邮件中问关于Struts 2实现文件上传的问题 ...
- salesforce 零基础学习(四十二)简单文件上传下载
项目中,常常需要用到文件的上传和下载,上传和下载功能实际上是对Document对象进行insert和查询操作.本篇演示简单的文件上传和下载,理论上文件上传后应该将ID作为操作表的字段存储,这里只演示文 ...
- JavaWeb学习记录(二十三)——文件上传与下载
一.导入jar包
- python接口自动化测试二十三:文件上传
# 以禅道为例: 一.创建一个类,类里面写一个登录方法: import requestsclass LoginZentao(): def __init__(self, s): # 初始化 self.s ...
- Netty学习(十)-Netty文件上传
今天我们来完成一个使用netty进行文件传输的任务.在实际项目中,文件传输通常采用FTP或者HTTP附件的方式.事实上通过TCP Socket+File的方式进行文件传输也有一定的应用场景,尽管不是主 ...
随机推荐
- 笔记:Spring Cloud Eureka 常用配置及说明
配置参数 默认值 说明 服务注册中心配置 Bean类:org.springframework.cloud.netflix.eureka.server.EurekaServerConfigBean ...
- 【Python】 Selenium 模拟浏览器 寻路
selenium 最开始我碰到SE,是上学期期末,我们那个商务小组做田野调查时发的问卷的事情.当时在问卷星上发了个问卷,但是当时我对另外几个组员的做法颇有微词,又恰好开始学一些软件知识了,就想恶作剧( ...
- java 二叉树排序
1 class BinaryTree{ 2 class Node{ 3 private Comparable data; 4 private Node left; 5 private Node rig ...
- 移动端H5地图矢量SHP网格切分打包方案
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 与离线瓦片方案一样,同样是为了解决移动端网速和流量问题,但是却 ...
- Beta冲刺链接总汇
Beta冲刺 咸鱼 Beta 冲刺day1 Beta 冲刺day2 Beta 冲刺day3 Beta 冲刺day4 Beta 冲刺day5 Beta 冲刺day6 Beta 冲刺day7 凡事预则立- ...
- 201621123062《java程序设计》第11周作业总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 思维导图: 2. 书面作业 本次PTA作业题集多线程 2.1. 源代码阅读:多线程程序BounceThread 2 ...
- 高级软件工程2017第6次作业--团队项目:Alpha阶段综合报告
高级软件工程2017第6次作业--团队项目:Alpha阶段综合报告 Deadline:2017-10-30(周一)21:00pm (注:以下内容参考集大作业4,集大作业5,集大作业6,集大作业7 一. ...
- Java 密码学算法
Java 密码学算法 候捷老师在< 深入浅出MFC 2e(电子版)>中引用林语堂先生的一句话: 只用一样东西,不明白它的道理,实在不高明 只知道How,不知道Why,出了一点小问题时就无能 ...
- 学号:201621123032 《Java程序设计》第6周学习总结
1:本周学习总结 1.1: 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图或相关笔记,对面向对象思想进行一个总结 2:书面作业 2.1: clone方法 2.1.1 ...
- 201621123057 《Java程序设计》第3周学习总结
1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系.步骤如下: 1.1 写出你 ...