combobox
当我在文件中使用以下代码时,我无法在 Struts2 中设置标签的字段
SUCCESS.JSP
:
<s:form>
<s:combobox label="Select and extract a field:" name="fieldname"
headerValue="--- Please Select ---" headerKey="1"
list="fields" listValue="myField" />
</s:form>
另一方面,我可以combobox
使用这种更直接的方式来填充,但这对我来说只是为了确保项目的结构是正确的:
<s:form>
<s:combobox label="Select and extract a field: " name="fieldsNames"
headerValue="--- Please Select ---"
headerKey="1" list="{'1','2','3','4','5','6'}" />
</s:form>
我对任何建议持开放态度,因为我尝试了很多事情,很明显我被卡住了。
其余的类和 XML 文件是:
COMBOBOX.JAVA
:
public class comboboxTag extends ActionSupport{
private List<String> fields;
private String myField;
private String fieldName;
public String getFieldName()
{
return fieldName;
}
public void setFieldName(String fieldName)
{
this.fieldName = fieldName;
}
public String getField()
{
return myField;
}
public void setField(String field)
{
this.myField = field;
}
public String execute()throws Exception
{
fields = new ArrayList<String>();
fields.add("1");
fields.add("2");
fields.add("3");
fields.add("4");
return SUCCESS;
}
public List<String> getFields()
{
return fields;
}
}
STRUTS.XML
:
<struts>
<constant name="struts.multipart.maxSize" value="19000000" />
<package name="fileUploadPackage" extends="struts-default">
<interceptors>
<interceptor-stack name="fileUploadStack">
<interceptor-ref name="exception" />
<interceptor-ref name="alias" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="debugging" />
<interceptor-ref name="profiling" />
<interceptor-ref name="scopedModelDriven" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="fileUpload">
<param name="maximumSize"> 18900000 </param>
<param name="allowedTypes"> application/pdf,text/plain</param>
</interceptor-ref>
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="actionMappingParams" />
<interceptor-ref name="params">
<param name="excludeParams"> dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="conversionError" />
<interceptor-ref name="validation">
<param name="excludeMethods"> input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods"> input,back,cancel,browse</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<!-- FILE UPLOAD ACTION -->
<action name="fileUpload" class="org.apache.fileUploadStruts.FileUploadAction">
<interceptor-ref name="fileUploadStack" />
<result name="input">/index.jsp</result>
<result name="success">/success.jsp</result>
</action>
<action name="comboboxTag" class="org.apache.fileUploadStruts.comboboxTag">
<result>/success.jsp</result>
</action>
</package>
INDEX.JSP
:
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Upload a File!!</title>
<s:head />
</head>
<body>
<s:form action="fileUpload" method="post" enctype="multipart/form-data" >
<s:file name="file" label="User File: " />
<s:submit />
</s:form>
</body>
</html>