Hi...I am new to struts2...Have any tell me how to pass struts action class variable into java script

At the risk of revealing my gross ignorance about struts, here's my best guess ...

Struts will forward either to a unique URL or to a more general URL with some query string in the path to indicate the required action.

If the page is unique (action is not determined by a quesrystring appended to the path) then there's most probably no need to pass the struts action class to javascript. It is implicit by the fact that that particular page has been served (containing whatever HTML/javascript as necessary).

If the page is not unique (action is determined by a quesrystring appended to the path) then you can do one of two things:

  1. Get javascript to read the action from the querystring. See my Query Parser for a way to do this. This is possible only if the page is served with eg. actionclass=... in the querystring.
  2. Write the action into javascript with JSP/PHP. Here is a PHP example:
    $actionClass = $_GET('actionClass');//sanitized as necessary to prevent code injection (though struts may immunize you from that).
    var actionClass = <?php =$actionClass ?>;

    I dare say it's similar in JSP if that's what you are using.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.