我可以使用struts2上传文件。但我想在 struts 2 中显示有关上传文件的详细信息 ( Filename
, filesize
, )。filetype
我正在尝试使用<s:property value="myFile" />
标签获取详细信息,但始终显示 [Object HTMLDocument]。
我的代码如下。
uploadfile.jsp
:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<div id="success-image">
<s:property value="myFile" />
<s:head theme="ajax" />
<s:form id="asset-upload" name="asset-upload" action="uploadFile.action" method="POST" theme="ajax" enctype="multipart/form-data">
<s:file name="myFile" label="Upload Image"/>
<s:submit targets="success-image" showLoadingText="false" indicator="uploading-image" id="asdf"/>
</s:form>
</div>
</body>
</html>
struts.xml
:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.multipart.maxSize" value="1000000000" />
<package name="default" extends="struts-default,json-default" namespace="/">
<action name="uploadFile" class="com.isam.struts.uploadFile">
<result name="success">
<param name="myFile">myFile</param>
</result>
<result name="error">login.jsp</result>
</action>
<action name="autoCompleterList" class="com.isam.struts.AutoCompleterList">
<result type="json" />
</action>
</package>
</struts>
UploadFile.java
:
package com.isam.struts;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import com.opensymphony.xwork2.ActionSupport;
public class uploadFile extends ActionSupport {
private File myFile;
private String myFileContentType;
private String myFileFileName;
private String destPath;
public String execute() {
/* Copy file to a safe location */
destPath = "C:/temp/";
try {
System.out.println("Src File name: " + myFile);
System.out.println("Dst File name: " + myFileFileName);
File destFile = new File(destPath, myFileFileName);
FileUtils.copyFile(myFile, destFile);
} catch (IOException e) {
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
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;
}
}
所以我应该在jsp文件中添加什么来显示细节,以及我应该在struts.xml
文件中添加什么