duke
duke

Reputation: 103

How to pass the sesssion value as hidden value in struts2?

I want to pass a session value as a hidden form value to an action class.

I have seen several examples but nothing worked for me; I get a null in the action.

Update.jsp:

<s:hidden name="name"  value="%{#session.sname}" />
<s:property value="#session.sname"></s:property>//works fine and printing username

User name is stored in session. I want to send this name to action class but I am unable to send.

UpdateAction.java:

public class UpdateAction extends ActionSupport {

    String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public string execute() {
       System.out.println("Username"+name);//getting null value
    }

}

Upvotes: 0

Views: 2577

Answers (1)

Sergio David Laserna
Sergio David Laserna

Reputation: 36

You should try:

<s:hidden value="%{#session['sname']}" name="aName"></s:hidden>

Upvotes: 2

Related Questions