当前位置: 代码迷 >> Java Web开发 >> struts1.2中action的嵌套有关问题
  详细解决方案

struts1.2中action的嵌套有关问题

热度:70   发布时间:2016-04-17 10:37:36.0
struts1.2中action的嵌套问题?
大家好,我目前需要提供一个页面让用户来创建问题,这个页面包含问题的title,type,priority,description等内容,但是type,priority是select型,它们的值是需要从数据库中去自动取得,然后显示在页面上供用户创建问题时选择。
目前我创建了一个optionAction,它的form包含title,type,priority,description等内容,然后它的action的excute函数从数据库读出type,priority的内容,最后显示一个jsp页面,这个页面作为用户创建问题的输入页面,所以我希望它转入到创建问题的action去创建一个问题放入到数据库中,请问该怎么做?
struts-config.xml中有:
  <action  
  attribute="optionForm"  
  name="optionForm"
  path="/selectOption"
  scope="request"
  type="org.springframework.web.struts.DelegatingActionProxy"
  validate="false">
  <set-property property="cancellable" value="true" />
  <forward name="success" path="/selectOption.jsp" />
  </action>

selectOption的action的excute函数如下:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {

List plist = new ArrayList();
List<String> li = bcService.findType();
plist.add(new SelectOption(" "," "));
for (int i = 0; i < li.size(); i++) {
String sp = li.get(i);
String id = Integer.toString(i);
System.out.println(sp);
System.out.println(id);
plist.add(new SelectOption(id,sp));
}

request.setAttribute("typeOptionList", plist);

List plo = new ArrayList();
li = bcService.findLocation();
plo.add(new SelectOption(" "," "));
for (int i = 0; i < li.size(); i++) {
String sp = li.get(i);
String id = Integer.toString(i);
System.out.println(sp);
System.out.println(id);
plo.add(new SelectOption(id,sp));
}

request.setAttribute("locationOptionList", plo);

List pri = new ArrayList();
li = bcService.findPriority();
pri.add(new SelectOption(" "," "));
for (int i = 0; i < li.size(); i++) {
String sp = li.get(i);
String id = Integer.toString(i);
System.out.println(sp);
System.out.println(id);
pri.add(new SelectOption(id,sp));
}

request.setAttribute("priorityOptionList", pri);
return mapping.findForward("success");
}

selectOption.jsp的内容是:
<body>
<html:form action="/selectOption">
<table width="100%">
<tr>
<td align="right" width="90">
<font color="red">*</font>&nbsp;Title
</td>
<td width="10"></td>
<td>
<html:text property="title" />
<font color="red"><span id="titleError"></span> </font>
</td>
</tr>
<tr>
<td align="right" width="90">
<font color="red">*</font>&nbsp;Type
</td>

<td>

<html:select property="type">
<html:options collection="typeOptionList"
labelProperty="displayname" property="id" />
</html:select>
<font color="red"><span id="typeError"></span> </font>

</td>
</tr>
<tr>
<td align="right" width="90">
<font color="red">*</font>&nbsp;Location
</td>

<td>

<html:select property="location">
  相关解决方案