我在遇到麻煩時,我使用的文件麻煩填充使用Struts 2的組合框
SUCCESS.JSP
在下面的代碼設置在Struts2一個combobox
標籤領域:
<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>
ComboBox的整個動作。這令人印象深刻。其實只有你需要的是返回你的清單的方法。 –