hardcode
hardcode

Reputation: 405

How to pass a Javascript variable to Struts param tag?

I tried to pass a Javascript variable to a struts param tag and I did it as follow:

 <script>
 var userName ="sample";
 </script>

 <body>
 <s:url action="myAction" id="myUrl">
 <s:param name="userName" value="%{userName}" />
 </s:url>
 </body>

But, it didn't work. Would somebody tell me how to do it?

Upvotes: 0

Views: 1595

Answers (1)

Gabriel Glenn
Gabriel Glenn

Reputation: 1264

You are confusing two very different things :

  • Struts runs in the server
  • Javascript runs in the browser

And as Struts will first render the html page, and then the page - html and javascript - will be interpreted by the browser, they is no way to pass a javascript variable to a Struts param.

in <s:param name="userName" value="%{userName}" />, userName should be a java bean, server side.

Upvotes: 1

Related Questions