具体是这样的,我在JSP页面中点击表单,想传递到ACTION中一个对象值,如果是STRING类型 用request.getAttribute("testno")就可以得到,但是如果变成对象 就无法取到。该对象就是一个主键,包括两个字段值。有没有高手可以解决啊!
最好给出具体解决的方案。在线等啊!

解决方案 »

  1.   

    如果是 User类  request.getAttribute("user.name")这样试试
      

  2.   

    你表单提交的时候 就可以用  <input type="text" name="user.name"/>   
    action里  直接get对象方法就可以得到了啊。。为什么还要用request.getAttribute()
      

  3.   

    <td width="120%">
    <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" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="id.rwh" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="id.gzh" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="xb" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="drawno" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="gzname" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="gzkind" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="pzrw" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="createdt" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="batchno" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="drawpiece" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="pages" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="edition" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="ljgxh" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="dhdw" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="num" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="unit" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="workshop" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="jdyq" />
    &nbsp;
    </td>
                                                <td>


    <a href="#"
    onclick="updateAction('<bean:write name="list" property="id"/>')">
    <img src="./images/right.gif" width="11" height="10"
    border="0" />
    </a>&nbsp;&nbsp; <a href="#"><img src="./images/right_01.gif" border="0" />
    </a>
    </td>


    </tr>
    </logic:iterate>
    </logic:notEmpty> </tbody> </table>
    表单的
      

  4.   

    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);
    }
    提交方法
      

  5.   

    public ActionForward execute(ActionMapping mapping, ActionForm form,
    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看看哪里出现问题了
      

  6.   

    把对象的属性拆开来,分别传给后台
    String no = request.getAttribute("no");
    String name = request.getAttribute("name");
    JSP哪里有那么高级,可以直接传对象?除非你用框架,struts的action可以帮你直接传递actionForm对象。不过它也是替你做了一些get,set的事情而已。你自己写,也一样。
      

  7.   

    你还是用的struts1   struts2是可以传对象的
      

  8.   

    现写的小例子,仅供参考:package com.wl.csdn.problem;public class User {    public String getUserName() {
            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进行配置了,
    具体的配置信息我就不写了
      

  9.   

    struts2 这样可以
    不是的话 可以拆成多个参数传过去
      

  10.   

    仔细看看我发的啊 我传递的是一个主键对象啊 如果就是USER PASSWOED什么的 能得到的 问题是主键是双字段的 只能传递对象
      

  11.   

    我现在的问题是取表格中的一行,这一行比方说就是RWFPB这个对象。主键就是ID,包括rwh,gzh两个,页面显示
    <td width="4%" align="center">
    <strong>任务号</strong>
    </td>
    <td width="4%" align="center">
    <strong>工装号</strong>
    </td>
    <td>
    <bean:write name="list" property="id.rwh" />
    &nbsp;
    </td>
    <td>
    <bean:write name="list" property="id.gzh" />
    &nbsp;
    </td>
    然后我取得主键这个对象
    <a href="#"
    onclick="updateAction('<bean:write name="list" property="id"/>')">
    <img src="./images/right.gif" width="11" height="10"
    border="0" />
    </a>&nbsp;&nbsp;
    调用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取得的就是空值。这么一套下来哪里有问题啊。