how can i pass value from javascript to a java class in struts2?

前端 未结 5 999
醉酒成梦
醉酒成梦 2020-12-21 18:15
function redirect(id){
alert(id);

document.forms[\"AddToCart\"].submit();
}

This is my javascript. How can i pass the value of \'id\' into AddToCa

5条回答
  •  不知归路
    2020-12-21 19:13

    We have to do two things to send a value to action class in struts2

    • send the required value with specific parameter name
    • create variable with the same name mentioned in jsp & create setter,getter methods for that variable.

    in action class

    public class AddToCart{
    private String itemId;
    
    public String getItemId(){
    return itemId;
    }
    public void setItemId(String id){
    this.itemId=id;
    }
    }
    

    this will work.

提交回复
热议问题