具体是这样的,我在JSP页面中点击表单,想传递到ACTION中一个对象值,如果是STRING类型 用request.getAttribute("testno")就可以得到,但是如果变成对象 就无法取到。该对象就是一个主键,包括两个字段值。有没有高手可以解决啊!
最好给出具体解决的方案。在线等啊!
最好给出具体解决的方案。在线等啊!
解决方案 »
- 本人刚进公司,遇到一个疑惑总是想不通,求解!
- js属性谁能帮我解释下
- 急需JSP论坛模板
- JSP 网页制作方面的问题...
- 怎样在javascript中调用hibernate?脑袋都快炸了,救命啊!~~~
- jspsmartupload 传文件,怎样改文件名称 ?
- 求大神解决xfire问题
- tomcat和oraled的连接池问题。在线等/
- 一个好多人问过的问题,可是我这里还是不能用,请在帮下忙
- 求Jrun3.01注册码,急
- 急,怎么在jsp中传递一个参数到java类,然后在这个jsp页面中显示java通过这个参数输出的一张图片,大哥大姐,帮帮忙!
- ACTION中 如何获得JSP页面传递过去的对象
action里 直接get对象方法就可以得到了啊。。为什么还要用request.getAttribute()
<table width="100%" border="1" cellspacing="0" cellpadding="0"
bordercolor="#BED9EC" bordercolordark="#FFFFFF"
style="line-height: 200%;" onclick="showDialog()">
<thead>
<tr style="background: url(./images/right_bgbj01.gif) repeat-x;"
height="27">
<td width="4%" align="center">
<strong>种类</strong>
</td>
<td width="4%" align="center">
<strong>任务号</strong>
</td>
<td width="4%" align="center">
<strong>工装号</strong>
</td>
<td width="4%" align="center">
<strong>型别</strong>
</td> <td width="4%" align="center">
<strong>零件号</strong>
</td>
<td width="5%" align="center">
<strong>工装名称</strong>
</td>
<td width="5%" align="center">
<strong>工装种类</strong>
</td>
<td width="5%" align="center">
<strong>品种任务</strong>
</td>
<td width="5%" align="center">
<strong>请制时间</strong>
</td>
<td width="4%" align="center">
<strong>批次</strong>
</td>
<td width="4%" align="center">
<strong>份数</strong>
</td>
<td width="4%" align="center">
<strong>页数</strong>
</td>
<td width="4%" align="center">
<strong>版次</strong>
</td>
<td width="6%" align="center">
<strong>零件工序号</strong>
</td>
<td width="6%" align="center">
<strong>订货 单位</strong>
</td> <td width="4%" align="center">
<strong>数量</strong>
</td>
<td width="4%" align="center">
<strong>单位</strong>
</td>
<td width="5%" align="center">
<strong>制造车间</strong>
</td> <td width="5%" align="center">
<strong>进度要求</strong>
</td>
</tr>
</thead>
<tbody>
<logic:notEmpty name="rwresultList">
<logic:iterate id="list" name="rwresultList">
<tr>
<td>
<bean:write name="list" property="kind" />
</td>
<td>
<bean:write name="list" property="id.rwh" />
</td>
<td>
<bean:write name="list" property="id.gzh" />
</td>
<td>
<bean:write name="list" property="xb" />
</td>
<td>
<bean:write name="list" property="drawno" />
</td>
<td>
<bean:write name="list" property="gzname" />
</td>
<td>
<bean:write name="list" property="gzkind" />
</td>
<td>
<bean:write name="list" property="pzrw" />
</td>
<td>
<bean:write name="list" property="createdt" />
</td>
<td>
<bean:write name="list" property="batchno" />
</td>
<td>
<bean:write name="list" property="drawpiece" />
</td>
<td>
<bean:write name="list" property="pages" />
</td>
<td>
<bean:write name="list" property="edition" />
</td>
<td>
<bean:write name="list" property="ljgxh" />
</td>
<td>
<bean:write name="list" property="dhdw" />
</td>
<td>
<bean:write name="list" property="num" />
</td>
<td>
<bean:write name="list" property="unit" />
</td>
<td>
<bean:write name="list" property="workshop" />
</td>
<td>
<bean:write name="list" property="jdyq" />
</td>
<td>
<a href="#"
onclick="updateAction('<bean:write name="list" property="id"/>')">
<img src="./images/right.gif" width="11" height="10"
border="0" />
</a> <a href="#"><img src="./images/right_01.gif" border="0" />
</a>
</td>
</tr>
</logic:iterate>
</logic:notEmpty> </tbody> </table>
表单的
alert(gzname);
document.forms[0].testNo.value=gzname;
document.forms[0].action="rwglupdate.do?testNo='"+gzname+"'";
document.forms[0].submit();
alert(gzname);
}
提交方法
HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
Object rwid = request.getSession().getAttribute("testNo"); //String gzname = request.getParameter("gzname"); ApplicationContext context = getWebApplicationContext();
Irwglservice service = (Irwglservice)context.getBean("rwglservice");
//Mom30100Form mom30100Form = (Mom30100Form) form;// TODO Auto-generated
Rwfpb rwfpb = service.findById((RwfpbId)rwid);
// method stub
rwglForm rwglForm = service.getrwglForm(rwfpb);
request.setAttribute("rwglForm", rwglForm);
ActionForward forward = mapping.getInputForward();
forward = mapping.findForward("success"); return forward; }
action看看哪里出现问题了
String no = request.getAttribute("no");
String name = request.getAttribute("name");
JSP哪里有那么高级,可以直接传对象?除非你用框架,struts的action可以帮你直接传递actionForm对象。不过它也是替你做了一些get,set的事情而已。你自己写,也一样。
return userName;
} public void setUserName(String userName) {
this.userName = userName;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String userName;
public String password;
}
Actionpackage com.wl.csdn.problem;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport { public User user;
public User getUser() {
return user;
} public void setUser(User user) {
this.user = user;
} @Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("userName="+user.getUserName());
System.out.println("password="+user.getPassword());
return SUCCESS;
}}
前台JSP<form action="login" name="form1" method="post">
UserName:<input type="text" name="user.userName" class="width154n" />
Password:<input type="text" name="user.password" class="width154n" />
<a href="#" onclick="javascript:document.form1.submit();">submit form</a>
</form>
前台提交按钮后,后台Action 中就可以获得User对象的值,当然了,还得需要对Struts2进行配置了,
具体的配置信息我就不写了
不是的话 可以拆成多个参数传过去
<td width="4%" align="center">
<strong>任务号</strong>
</td>
<td width="4%" align="center">
<strong>工装号</strong>
</td>
<td>
<bean:write name="list" property="id.rwh" />
</td>
<td>
<bean:write name="list" property="id.gzh" />
</td>
然后我取得主键这个对象
<a href="#"
onclick="updateAction('<bean:write name="list" property="id"/>')">
<img src="./images/right.gif" width="11" height="10"
border="0" />
</a>
调用function updateAction(gzname){
alert(gzname);document.forms[0].testNo.value=gzname;document.forms[0].action="rwglupdate.do?testNo='"+gzname+"'"; document.forms[0].submit();
alert(gzname);
}
这个方法传递参数(对象)。
在ACTION中取得这个对象
Object rwid = request.getSession().getAttribute("testNo");
在这里rwid取得的就是空值。这么一套下来哪里有问题啊。