`
收藏列表
标题 标签 来源
struts2标签前台截取字符串长度 struts2
<s:iterator value="forums" id="for">
				<tr>
					<td align="center">
						${title }
					</td>
					<s:set name="str" value="#for.content">
						<td align="center">
							<s:if test="%{#str.length()>20}">
								<s:property value="#str.substring(0,21)+'...'" />
							</s:if>
							<s:else>
								<s:property value="str" />
							</s:else>
						</td>
					</s:set>
					<td align="center">
						${createtime }
					</td>
					<td align="center">
						${type }
					</td>
					<td align="center">
						<a href="./forum/deleteforum.action?forum.id=${id }"
							style="text-decoration: none">删除</a>
					</td>
				</tr>
			</s:iterator>
struts2文件批量上传 struts2
import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class BatchUpload extends ActionSupport {

 /**
  * 
  */
 private static final long serialVersionUID = 2160200185775231663L;

 private File[] file;//接收上传的文件

 private String[] fileFileName;//struts2提供的格式,在文件名后面+FileName就是上传文件的名字

 private String[] fileContentType;

 public File[] getFile() {
  return file;
 }

 public void setFile(File[] file) {
  this.file = file;
 }

 public String[] getFileFileName() {
  return fileFileName;
 }

 public void setFileFileName(String[] fileFileName) {
  this.fileFileName = fileFileName;
 }

 public String[] getFileContentType() {
  return fileContentType;
 }

 public void setFileContentType(String[] fileContentType) {
  this.fileContentType = fileContentType;
 }

 public String bachUpload() {
  String realPath = ServletActionContext.getServletContext().getRealPath(
    "upload");
  if (file != null && file.length > 0) {
   for (int i = 0; i < file.length; i++) {
    File saveFile = new File(new File(realPath), fileFileName[i]);
    if (!saveFile.getParentFile().exists()) {
     saveFile.mkdirs();
    }
    try {
     FileUtils.copyFile(file[i], saveFile);
    } catch (IOException e) {
     e.printStackTrace();
    }
   }
  }

  return "success";
 }
}
Global site tag (gtag.js) - Google Analytics