使用Struts+hibernate开发时 表单数据Action获取不到

tiandandexia 2014-03-30 09:40:23
【做毕业设计时 使用使用Struts+hibernate,问题: 页面【更新】或【新增】操作时提交表单Action获取不到提交的参数】

在ClubTypeAction中定义的一个参数此参数是用来解决表单无法提交对象型数据定义的,通过相应的get方法set到Action中要处理的DomainModel中去,进而通过Hibernate存储到数据库中。结果这个中间参数的值获取不到。
Jsp页面是可以通过document.getElementById("xxx").value获取到这个值的
还是上代码吧,希望各位朋友帮忙解答一下
struts.xml

<action name="clubType" class="cn.chzu.csci.action.ClubTypeActon" method="update">
<result type="redirect">/background/sys_admin/dictionaryManage/clubType_list.jsp</result>
<result name="input" type="redirect">/background/sys_admin/sysUserManage/sysUser_update.jsp</result>
</action>

jsp代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@page import="cn.chzu.csci.domain.dictionary.ClubType"%>
<%@page import="cn.chzu.csci.service.ClubType_Service"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
ClubType_Service service = new ClubType_Service();
ClubType clubType = service.getById(Integer.parseInt(request.getParameter("id")));
%>
<html>
<head>
<base href="<%=basePath%>" />
<title>更新用户信息</title>
<script type="text/javascript">
function check(){
name = document.getElementById("name").value;
statusItemCode=document.getElementsByName("statusItemCode").value;
if(name.replace(/(^\s*|\s*$)/gi,'') === ''){
alert("姓名不能为空!");
return false;
}
alert("取到值啦"+name);
return confirm("确定修改?")

}
</script>


<style>
.title {
font-size: 16px;
font-family: "楷体";
color: #000000;
font-weight: bold;
}
</style>

</head>
<body>
<s:bean name="cn.chzu.csci.service.IsUse_Service" var="sexType_db"></s:bean>
<s:set var="list" value="%{#sexType_db.list()}"></s:set>
<s:bean name="cn.chzu.csci.service.ClubType_Service" var="db"></s:bean>
<s:set var="clubType" value="%{#db.getById(#parameters.id)}"></s:set>
<s:if test="{#session.msg}" >
<s:property value="%{#session.msg}"/>
<%session.removeAttribute("msg"); %>
</s:if>
<!--update/clubType-->
<form action="<%=basePath%>update/test!update.action" method="post">
<input type="hidden" id="clubType_id" name="clubType.id" value="<%=clubType.getId()%>" />

<table width="100%" border="1" height="400" bordercolor="#bae87c">
<tr>
<td height="49" colspan="5">
<strong>社团类型修改</strong>
</td>
</tr>
<tr>
<td width="5%" height="400s">
 
</td>

<td colspan="3">
<table width="100%" border="1" bordercolor="#bae87c" height="400">
<tr>

<td width="25%" class="title">
<font color="#FF0000">*</font>社团类型
</td>
<td width="25%">
<input type="text" class="title" id="username"
name="clubType.itemValue" value="<%=clubType.getItemValue()%>" />
</td>
<td width="25%" class="title">
描  述
</td>
<td width="25%">
<input type="text" class="title" id="password"
name="clubType.description" maxlength="40"
value="<%=clubType.getDescription()%>" />
</td>
</tr>
<tr>
<td class="title">
<font color="#FF0000">*</font>状  态
</td>
<td>
<s:select id="name" name="isUseCode" theme="simple" list="list" cssClass="title"
listKey="itemCode" cssStyle="width:168px" value="%{#clubType.getIsUse().getItemCode()}"
listValue="itemValue" onchange="check()">
</s:select>
</td>
<td class="title">
注册时间
</td>
<td>
<input type="text" class="title" id="entranceTime"
name="clubType.createTime"
value="<%=clubType.getCreateTime()%>" />
</td>
</tr>
<tr>
<td colspan="4">
<div align="center">
<input type="submit" class="title" value="修改" onClick="return check()"/>
<input type="button" class="title" value="取消"
onclick="location.href='<%=basePath%>background/sys_admin/dictionaryManage/clubType_list.jsp'"></input>
</div>
</td>
</tr>
</table>
</td>

<td width="8%">
 
</td>
</tr>
<tr>
<td height="37" colspan="5">
</tr>
</table>
<!-- 修改信息页面 -->
</form>
</body>
<s:debug></s:debug>
</html>

ClubTypeAction.action
package cn.chzu.csci.action;

import cn.chzu.csci.domain.dictionary.ClubType;
import cn.chzu.csci.domain.dictionary.IsUse;
import cn.chzu.csci.service.ClubType_Service;
import cn.chzu.csci.service.IsUse_Service;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction extends ActionSupport{
private int isUseCode;
private ClubType clubType;
private ClubType_Service clubTypeService = new ClubType_Service();
private IsUse_Service isUseService = new IsUse_Service();
public int getIsUseCode() {
return isUseCode;
}
public void setIsUseCode(int isUseCode) {
this.isUseCode = isUseCode;
}
public ClubType getClubType() {
return clubType;
}
public void setClubType(ClubType clubType) {
this.clubType = clubType;
this.clubType.setIsUse(isUseService.getById(getIsUseCode()));
}
public ClubType_Service getClubTypeService() {
return clubTypeService;
}
public void setClubTypeService(ClubType_Service clubTypeService) {
this.clubTypeService = clubTypeService;
}
public IsUse_Service getIsUseService() {
return isUseService;
}
public void setIsUseService(IsUse_Service isUseService) {
this.isUseService = isUseService;
}
public String add(){
clubTypeService.add(clubType);
return SUCCESS;
}
public String update(){
clubTypeService.update(clubType);
return SUCCESS;
}


}
...全文
133 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tiandandexia 2014-03-31
  • 打赏
  • 举报
回复
TestAction 那一段粘错了
木鱼121 2014-03-31
  • 打赏
  • 举报
回复
为什么 你xml中" class="cn.chzu.csci.action.ClubTypeActon"的类是这个 而你粘贴的java类名字是public class TestAction 这个呢?
tiandandexia 2014-03-31
  • 打赏
  • 举报
回复
页面form中的值与Action中定义是一致的,结果还是出现这个问题
JavaMan 2014-03-30
  • 打赏
  • 举报
回复
页面中 控件的 name 值应该与action 中属性名 一致。否则收不到数据。
rmengshu 2014-03-30
  • 打赏
  • 举报
回复
java action类中试试把private int isUseCode; 改成private String isUseCode; 再重新get,set下。我的理解是类型匹配不上。(ps:你这样只能获得选中的值哈)
tiandandexia 2014-03-30
  • 打赏
  • 举报
回复
就是那个isUseCode 取不到值

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧