发现这个问题好难啊~~

chinatan 2006-04-19 05:36:54
编辑数据时,action中的数据是如何显示到jsp页面的?有个要求是:新增数据的页面要和编辑数据的页面共用一个页面(既都是userAdd.jsp)

我在userAddAction中已经把数据成功的放到相应的userAddForm中了,把数据放到userAddForm中之后就return mapping.findForward("Edit");到userAdd.jsp页面拉,但是数据在userAdd.jsp上显示不出来。(单步调试检查时userAddForm中已经有了正确的值。也不报任何的错误,就是userAdd.jsp中没有显示任何数据。)

初学者遇到如此棘手的问题,望高手们帮忙解惑。谢谢!!

userAddAction中的doEdit方法:

private ActionForward doEdit(
ActionMapping mapping,UserAddForm userAddForm,HttpServletRequest request,HttpServletResponse

response)
{
int userId=userAddForm.getUserId();//从userAddForm中获取要修改用户的userId号,
try {
String sql = "select * from userInfo where userId='"+userId+"'";

PublicDataOperation po = new PublicDataOperation();
ResultSet rs = po.executeQuery(sql,null);
RowSetDynaClass rsdc = new RowSetDynaClass(rs);
List list = rsdc.getRows();//把要编辑的数据记录集返回并且保存到List中
//request.setAttribute("userList",list);
//使用了动态Bean
DynaBean dyna = (DynaBean)list.get(0);//使用动态Bean把list中的数据取出来,再放到UserAddForm当中。

String userName = (String)dyna.get("username");
String userSex =(String)dyna.get("usersex");
String birthday =(String)dyna.get("birthday");
String email =(String)dyna.get("email");
String phone =(String)dyna.get("phone");
String mobilePhone =(String)dyna.get("mobilephone");
String province =(String)dyna.get("province");
String description =(String)dyna.get("description");
String publish =(String)dyna.get("publish");
userAddForm.setUserName(userName);
userAddForm.setUserSex(userSex);
userAddForm.setBirthday(birthday);
userAddForm.setEmail(email);
userAddForm.setPhone(phone);
userAddForm.setMobilePhone(mobilePhone);
userAddForm.setProvince(province);
userAddForm.setDescription(description);
userAddForm.setPublish(publish);
} catch (SQLException e) {// TODO Auto-generated catch block
e.printStackTrace();return mapping.findForward("Failure");}

return mapping.findForward("Edit");//跳转到userAdd.jsp页面。
}



(userAdd.jsp页面代码:)



<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page language="java" contentType="text/html;charset=GBK"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html locale="true">
<head>

<html:base />

<title>userAdd.jsp</title>
<SCRIPT LANGUAGE="JavaScript">
<!--
function onSubmit(){
document.UserAddForm.action.value="Save";
document.UserAddForm.submit();
}
//-->
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>

<body>

<html:form action="/userAdd" name="UserAddForm" method="POST"

type="com.yourcompany.struts.form.UserAddForm">
<br>
<br>
<br>
<div align="center">
<html:hidden property="action"/>
<html:hidden property="userId"/>
<CENTER><FONT SIZE="3" COLOR="">新 增 用 户</FONT></CENTER>
<br>
<br>
<table border="0" width="98%" height="35" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><INPUT TYPE="button" value="保 存" onclick="onSubmit()">
</td>
<td width="100%">
<p align="right"><INPUT TYPE="button" value="返 回"

onclick="javascript:window.location='userAdd.do?action=success'">
</td>
</tr>
</table>
<TABLE border="0" width="60%">
<TR>
<TD width="15%" align="right">名 称:</TD>
<TD><html:text property="userName"/><bean:write name="UserAddForm"

property="userName"/></TD>
</TR>
<TR>
<TD width="15%" align="right">性 别:</TD>
<TD><html:radio property="userSex" value="0" />男<html:radio property="userSex" value="1"

/>女</TD>
</TR>
<TR>
<TD width="15%" align="right">出生年月:</TD>
<TD><html:text property="birthday"/></TD>
</TR>
<TR>
<TD width="15%" align="right">电子邮件:</TD>
<TD><html:text property="email"/></TD>
</TR>
<TR>
<TD width="15%" align="right">电话号码:</TD>
<TD><html:text property="phone"/></TD>
</TR>
<TR>
<TD width="15%" align="right">手机号码:</TD>
<TD><html:text property="mobilePhone"/></TD>
</TR>
<TR>
<TD width="15%" align="right">省 份:</TD>
<TD><html:text property="province"/></TD>
</TR>
<TR>
<TD width="15%" align="right">个人描述:</TD>
<TD><html:text property="description"/></TD>
</TR>
<TR>
<TD width="15%" align="right">是否公开:</TD>
<TD><html:text property="publish"/></TD>
</TR>
</TABLE>
</div>
</html:form>

</body>
</html:html>



...全文
262 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
procz 2006-04-22
  • 打赏
  • 举报
回复
没有仔细的看:传递值无非就是把值放入request中或根据类来返回一个值,如果是使用request如下:

如: request.setAttribute("aaaa",变量);

在jsp页面上直接就可以,假如是一个String变量:
String bbb = (String)request.getAttribute("aaaa");

如果是其他的对象,一样的道理,把String换成其他,道理一样. 不过不要把什么都放入session中,看使用的范围;如果要使用,那使用完了,记得remove掉.


LoveFly_Zero 2006-04-21
  • 打赏
  • 举报
回复
validate="false"改成validate="true"
你都没在Form里进行验证,肯定不行的呀
EchoEverything 2006-04-21
  • 打赏
  • 举报
回复
我感觉也是没有把必要的对象放到session里面
sgdb 2006-04-21
  • 打赏
  • 举报
回复
session.setAttribute("userAddForm", userAddForm);

return mapping.findForward("Edit");
hello_vv 2006-04-20
  • 打赏
  • 举报
回复
你的userAddForm的作用域只在当前action里,你转向另一个页面当然接收不了了
chinatan 2006-04-20
  • 打赏
  • 举报
回复
高手们呢?
chinatan 2006-04-20
  • 打赏
  • 举报
回复
to hello_vv()
你的userAddForm的作用域只在当前action里,你转向另一个页面当然接收不了了----------

我录入数据时也是用这个userAddAction和userAddForm啊,录入数据的操作是成功的。编辑时候也是使用了同样的userAddAction和userAddForm啊,并且录入数据和编辑数据共用的是同一个页面(userAdd.jsp),但是编辑时,数据就是没有出现到userAdd.jsp页面上,狂郁闷~~~~~
chinatan 2006-04-19
  • 打赏
  • 举报
回复
自己顶一下~~

相关配置文件如下:

<struts-config>
<data-sources />
<form-beans >
<form-bean name="userAddForm" type="com.yourcompany.struts.form.UserAddForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="userAddForm"
input="/userAdd.jsp"
name="userAddForm"
path="/userAdd"
scope="request"
type="com.yourcompany.struts.action.UserAddAction"
validate="false">
<forward name="Failure" path="/Error.jsp" />
<forward name="ShowAdd" path="/userAdd.jsp" />
<forward name="Edit" path="/userAdd.jsp" />
<forward name="success" path="/UserList.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

67,550

社区成员

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

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