为什么我的Action中的不到对应的ActionForm,请大侠指教!
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="userForm"
type="com.struts.ActionForm.UserActionForm" />
</form-beans>
<action-mappings>
<action path="/display"
type="com.struts.Action.DisplayAction"
scope="request">
<forward name="success" path="/manager.jsp"/>
</action>
<action path="/add"
type="com.struts.Action.AddAction"
scope="request">
<forward name="success" path="/add.jsp"/>
</action>
<action path="/doAdd"
type="com.struts.Action.DoAddAction"
scope="request" name="userForm">
<forward name="success" path="/manager.jsp"/>
</action>
<action path="/del"
type="com.struts.Action.DelAction"
name="userForm"
scope="request">
<forward name="success" path="/manager.jsp"/>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
这个配置文件!
页面代码:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %>
<%@ taglib prefix="logic" uri="http://struts.apache.org/tags-logic" %>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>维护页面</title>
<script type="text/javascript">
function getAll()
{
var cb =document.getElementById("getCB");
var allcb=document.getElementsByName("selcetFlag");
if(cb.checked==true)
{
for(var i=0;i<allcb.length;i++)
{
allcb[i].checked=true;
}
}else {
for(var i=0;i<allcb.length;i++)
{
allcb[i].checked=false;
}
}
}
function doIt(road)
{
document.form1.action=road;
document.form1.submit();
}
</script>
</head>
<body>
<form action="" name="form1" method="post">
<em><strong>系统管理>>用户维护</strong></em><br>
<hr>
<table border="1" width=100%>
<tr align="left"><th colspan="5">列表查询</th></tr>
<tr>
<td align="center">
<input type="checkbox" id="getCB" name="cball" onclick="getAll()"/>
</td>
<td align="center">用户代码</td>
<td align="center">用户名称</td>
<td align="center">联系电话</td>
<td align="center">email</td>
</tr>
<logic:empty name="list">
<tr><td colspan="5" align="center">没有数据</td></tr>
</logic:empty>
<logic:notEmpty name="list">
<logic:iterate id="user" name="list">
<tr align="center">
<td align="center"> <input type="checkbox" name="selectFlag" value="<bean:write name="user" property="id"/>"/></td>
<td align="center"><bean:write name="user" property="id"/></td>
<td align="center"><bean:write name="user" property="userName"/> </td>
<td align="center"><bean:write name="user" property="tel"/></td>
<td align="center"><bean:write name="user" property="email"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
<tr>
<td colspan="5" align="right">
共xx页 当前第x页
<html:button property="add" value="添加" onclick="doIt('add.do')"/>
<html:button property="del" value="删除" onclick="doIt('del.do')"/>
<html:button property="update" value="修改" onclick="doIt('update.do')"/>
<td>
</tr>
</table>
</form>
</body>
</html>
为什么我的delAction中的不到userForm??
[解决办法]
1.在action中直接填入/del.do 获取ID
2.不用actionform 直接传入ID 进行删除
[解决办法]
绑定下就行了
[解决办法]
form-beans>
<form-bean name="userForm"
type="com.struts.ActionForm.UserActionForm" />
</form-beans
这个设置好像不对
删除的话应该这样
<form-bean name="deleteform"
type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="deptid" type="java.lang.Integer[]"></form-property>
</form-bean>
得到id数组就可以了
应该这样设置然后ACtion里form.get("dept")就可以了吧
<form-bean name="deptform"
type="org.apache.struts.validator.DynaValidatorActionForm">
<form-property name="dept" type="dfbz.yiyang.persist.Dept" />
</form-bean>