anichhangani anichhangani - 8 months ago 88
Java Question

Passing parameter from view to action in Struts 2

I am trying to pass a value in JavaScript variable (i.e an access token from Facebook) from the view section of the framework to action where the corresponding Java object variable is stored.

What are the possible ways to do this?


Create a hidden field and save the value in it. Access the action via submitting a form like in this answer. The example of saving a value to a hidden field using jQuery

<s:hidden name="myHiddenField"/>
<script type="text/javascript">
  function saveValue(value) {

In the action class you should have a property for myHiddenField

public class MyAction extends ActionSupport {
  private String myHiddenField;
  //getters and setters here 

now you configure the action to execute using defaultStack of interceptors and when you submit the form the field will be populated to the action object.