struts1.2中action的嵌套问题?
时间:2011-12-16
来源:互联网
大家好,我目前需要提供一个页面让用户来创建问题,这个页面包含问题的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> 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> 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> Location
</td>
<td>
<html:select property="location">
<html:options collection="locationOptionList"
labelProperty="displayname" property="id" />
</html:select>
<font color="red"><span id="typeError"></span> </font>
</td>
<td align="right" width="90">
<font color="red">*</font> priority
</td>
</tr>
<tr>
<td>
<html:select property="priority">
<html:options collection="priorityOptionList"
labelProperty="displayname" property="id" />
</html:select>
<font color="red"><span id="typeError"></span> </font>
</td>
</tr>
<tr><td width="90" align="right"><html:submit /></td></tr>
</table>
</html:form>
</body>
上面这些都能运行正确。最后selectOption.jsp能显示出一个正确的信息。这个页面收集了创建问题需要的所有信息。
下面我希望这个页面的内容传入给创建问题的action去创建问题,请问我该怎么做了?
谢谢!我是新手,分数也不够了。谢谢各位!
目前我创建了一个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> 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> 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> Location
</td>
<td>
<html:select property="location">
<html:options collection="locationOptionList"
labelProperty="displayname" property="id" />
</html:select>
<font color="red"><span id="typeError"></span> </font>
</td>
<td align="right" width="90">
<font color="red">*</font> priority
</td>
</tr>
<tr>
<td>
<html:select property="priority">
<html:options collection="priorityOptionList"
labelProperty="displayname" property="id" />
</html:select>
<font color="red"><span id="typeError"></span> </font>
</td>
</tr>
<tr><td width="90" align="right"><html:submit /></td></tr>
</table>
</html:form>
</body>
上面这些都能运行正确。最后selectOption.jsp能显示出一个正确的信息。这个页面收集了创建问题需要的所有信息。
下面我希望这个页面的内容传入给创建问题的action去创建问题,请问我该怎么做了?
谢谢!我是新手,分数也不够了。谢谢各位!
作者: wztk0001 发布时间: 2011-12-16
你可以在创建问题的action转发的页面中引进这个jsp页面就行了吧 ,你引进时这个页面已经经过处理了
作者: zhourrr1234 发布时间: 2011-12-16
引用 1 楼 zhourrr1234 的回复:
你可以在创建问题的action转发的页面中引进这个jsp页面就行了吧 ,你引进时这个页面已经经过处理了
你可以在创建问题的action转发的页面中引进这个jsp页面就行了吧 ,你引进时这个页面已经经过处理了
能否举个例子?多谢!
现在在struts-config.xml中,创建问题的action该怎么写呢?我现在按照下面的方式来写,与上面的action共用form,没有成功。
<action
attribute="optionForm"
name="optionForm"
path="/createProblem"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="false">
<set-property property="cancellable" value="true" />
<forward
name="failure"
path="/selectOption.jsp"
redirect="true" />
<forward name="success" path="/listProblem.do" />
</action>
作者: wztk0001 发布时间: 2011-12-16
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28