0

I'm using struts2 for front end framework and found this issue which need to be resolved. So I view the page with edit privilege for this url

 [CONTEXT]/getUser.do?userId=1

But when I click Submit button, it seems struts render my request uri to getUser.do without any URL parameter. It also displayed in my result url

 [CONTEXT]/getUser.do

From this SO solution I knew I can use struts hidden tag. But using that tag will not change the result URL. I want the URL parameter passed to java action, as well as change the URL result.

If I using s:url tag, it need to know the value beforehand (is it?).

<s:url id="xyzUrl" action="xyz" includeContext="false"><s:param name="user" value="george"/></s:url> 

If using s:url tag, how can I pass dynamic value given by url parameter(in url browser) to the value argument of struts url tag? And can this solution resolve both of view mode(display page in the first time) and submit mode(submit the displayed page)?

Community
  • 1
  • 1
Barjack
  • 49
  • 9
  • What do you want to know from [that SO solution](http://stackoverflow.com/questions/13373760/how-to-pass-a-parameter-in-url-on-a-form-submit-in-struts2)? – Roman C Nov 10 '16 at 11:27
  • @RomanC from that solution, the url parameter will be added to url string only for GET method. While I need it in POST method also. My example above, if I set the success result to the same url, it wont write the url parameter to the url string. – Barjack Nov 11 '16 at 09:45
  • I didn't use GET in my answer. – Roman C Nov 11 '16 at 12:25
  • Ah you're the one who answer using s:url. It doesnt work for me. Do we have to include " " in our struts.xml? I'll update the question to give more info – Barjack Nov 11 '16 at 13:10
  • @RomanC actually it worked! I misread your solution when in form tag we fill action value with %{id value in s:url tag} But, tag s:url always write the url in my page(as content in my html body). How can I delete this text? – Barjack Nov 11 '16 at 13:30
  • Struts used `id` attribute in previous versions, in newer versions you should use `var` instead. – Roman C Nov 11 '16 at 13:34
  • if I use "var", the parameter will not included again. With "id" it worked @RomanC but the url text keep displayed in my page. ' ' – Barjack Nov 11 '16 at 14:27
  • I don't see where the url parameter is applied. – Roman C Nov 11 '16 at 21:20
  • @RomanC Because I simply want to include the url parameter in GET request. For example, my GET request is [CONTEXT]/getUser.do?userId=10. And then on that page I do submit (POST) process, then by default the previous userId will not included in next url. After I click submit, the url will automatically be [CONTEXT]/getUser.do , without userId=10 – Barjack Nov 12 '16 at 03:54
  • Bu you didn't include any parameter in the `url`tag. Parameters are created via `param` tag. – Roman C Nov 12 '16 at 11:41

0 Answers0