我定义了一个类继续 ActionSupport 在中间定义了一个showRoleName()方法,中间带了一个参数 如:
  public class Roleaction extends ActionSupport {   private Integer roleId;
  private String roleName;
  private Integer userId;
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
   public RoleBean showRoleName(Integer userId)
{
RoleBean bean=new RoleBean();
    this.roleoperationImpl.viewRole(1);
return bean;
}
}
我在struts.xml 中配置的是:
<action name="roleOP" class="com.colavia.action.Roleaction" method="showRoleName">
    
    </action>
我要如何在页面上 调用showRoleName()带参数的 这个方法了

解决方案 »

  1.   

      function testShow()
      {
      alert("sfsf");
       document.forms[0].action="roleOP";
       document.forms[0].submit();
        }
    随便在我是在页面这样调用的,这样调用会报
    java.lang.NoSuchMethodException: com.colavia.action.Roleaction.showRoleName()
    找不倒这一个方法。。
      

  2.   

    继承了以后要重写execute()这个方法吧,在这个方法里调用就可以了。当转向action的时候,就会自动执行execute()方法。
      

  3.   

    如果想要传个参,看来你只能重写下execute()方法,然后再这个方法里调用你的方法!因为你自定义的方法不是一个标准的可以让struts2自动调用的方法的格式!
      

  4.   

    如果非要调用这个由参数的方法的话,也许根本无法实现,我不知道,!但是,你完全可以把参数隐藏到JSP画面,然后提交到Action来解决这个问题。希望对你有帮助。
      

  5.   

    方法签名有误,应该是 public String showRoleName() 
     
      

  6.   

      那是不是说action 不能够执行这一个带参数的方法了。
      

  7.   

    struts2玩到现在作为跳转action的方法要带参数干啥?在action中定义属性后参数在方法里面就可以取到,为什么还要传呢?