Struts将参数从jsp传递给action

时间:2012-12-05 13:06:55

标签: java struts

我使用Struts 2.2。

我已经迭代了ArrayList个用户。我有一个每个用户的编辑链接。

单击编辑链接时,我想在数据库中找到该用户并显示其属性。

不幸的是,链接不会将我带到所需的页面,而是将其重定向到同一页面。有什么想法吗?

display.jsp:

<logic:iterate id="customerElement" name="ACTIVE_PROFILES_LIST" property="list">
  <tr>
    <td>
      <bean:write name="customerElement" property="lastName"/>
    </td>

    <td>
      <bean:write name="customerElement" property="firstName"/>
    </td>

    <td>
      <pdk-html:link action="/beforeEditProfile.do?toEdit=${customerElement.login}">Edit</pdk-html:link>
    </td>
  </tr>
</logic:iterate> 

动作类:

public class BeforeBeforeEditProfileAction(){

  public ActionForward execute(ActionMapping mapping, ActionForm form,
                               HttpServletRequest request,
                               HttpServletResponse response) throws IOException,
                                                                    ServletException {


 // retrieve the parameter


    String toModify= request.getParameter("toEdit");  
    SearchBean search = new SearchBean();
    Cetatean cet = search.getSingleCitizen(toModify);
    LogManager.info("BeforeEditProfileAction: ENTER");
    if(cet!=null){
        request.setAttribute("cetatean", cet);
        LogManager.info("BeforeEditProfileAction: cetatean not null");
        return mapping.findForward("succes");
    }
    else {  
        LogManager.info("BeforeEditProfileAction: cetatean null");
        return  mapping.findForward("failure");
    }

  }
 }

的struts-config.xml

<action path="/beforeEditProfile" type="pm.action.BeforeEditProfileAction" name="user" validate="true" scope="request" input="/htdocs/pages/display.jsp">
  <forward name="success" path="/htdocs/pages/editProfile.jsp"/>
  <forward name="failure" path="/htdocs/pages/profileEditedFailed.jsp"/>

0 个答案:

没有答案