2 つのページに struts ファイルのアップロードがある struts 2 アプリケーションがあります。1つは完全に機能しますが、もう1つは機能しません。「フィールド "secImage" のフィールド値が無効です。
これがJSPのコードです
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="http://displaytag.sf.net" prefix="display" %>
<html>
<head>
</head>
<body>
<%@ include file="header.jsp" %>
<s:form action="Test" method="POST" style="width:90%;">
Another form here......
</s:form>
<s:form action="Test" method="POST" enctype="multipart/form-data">
<s:push value="secVul">
<s:hidden name="vulId" />
<s:hidden name="scanHistory.scanId" />
<s:textfield name="protocol" label="Protocol" style="width: 80%;" />
<s:textarea name="description" label="Description" style="width: 80%;" />
<s:textarea name="solution" label="solution" />
<more form elements here>sdfasdfasdfasd
<s:file name="secImage" label="Image to Upload" size="40"/>
<s:submit value="Add/Update" align="center"/>
</s:push>
</s:form>
<%@ include file="footer.jsp" %>
</body>
</html>
これがストラット構成です
<interceptor-ref name="fileUpload">
<param name="maximumSize">909715200</param>
<param name="allowedTypes">
text/xml,application/octet-stream,image/png,image/gif,image/jpeg,image/pjpeg
</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<action name="Test" method="saveOrUpdate" class="com.Test">
<result name="success" type="redirect">listVulsMGR</result>
<result name="input">/WEB-INF/pages/secVuls.jsp</result>
<result name="error">/WEB-INF/pages/secVuls.jsp</result>
</action>
アクション クラス コード:
public class Test extends ActionSupport implements ModelDriven<Test>, Preparable,ServletRequestAware {
private HttpServletRequest servletRequest;
private static final Logger logger = Logger.getLogger(ListVulsActions.class);
private File secImage;
private String secImageContentType;
private String secImageFileName;
private HashMap userFilters = new HashMap();
public Test() {
}
public String saveOrUpdate() {
try {
ServletContext context = ServletActionContext.getServletContext();
String filePath = context.getInitParameter("UploadDirectory");
logger.debug("Server path:" + filePath);
logger.debug("this.secImageFileName " + this.secImageFileName);
File fileToCreate = new File(filePath, this.secImageFileName);
FileUtils.copyFile(this.secImage, fileToCreate);
}
addActionMessage("successfully added/updated.");
return SUCCESS;
} catch (Exception ex) {
logger.error("Error in Test", ex);
addActionError("Error occured in Test. Please contact your administrator.\n" + ex.getMessage());
return ERROR;
}
}
public File getSecImage() {
System.out.println(secImage.getName());
return secImage;
}
/**
* @param secImage the secImage to set
*/
public void setSecImage(File secImage) {
System.out.println(secImage.getName());
this.secImage = secImage;
}
/**
* @return the secImageContentType
*/
public String getSecImageContentType() {
System.out.println(secImageContentType);
return secImageContentType;
}
/**
* @param secImageContentType the secImageContentType to set
*/
public void setSecImageContentType(String secImageContentType) {
System.out.println(secImageContentType);
this.secImageContentType = secImageContentType;
}
/**
* @return the secImageFileName
*/
public String getSecImageFileName() {
System.out.println(secImageFileName);
return secImageFileName;
}
/**
* @param secImageFileName the secImageFileName to set
*/
public void setSecImageFileName(String secImageFileName) {
System.out.println(secImageFileName);
this.secImageFileName = secImageFileName;
}
@Override
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest;
}
ここで何が間違っているのかわかりません。ヘルプ/ヒントをいただければ幸いです
--