Form- Action Attribute value

心已入冬 提交于 2019-12-25 04:22:48

问题


What does it mean if I am setting the action attribute of form element set to "?" ?

In my application the form element is :

 <form action = "?" commandName="demoPageForm" method="POST">
 .......
 </form>

In controller I am having like:

   @RequestMapping(value = "/getDemoPage", method = RequestMethod.POST)
   public ModelAndView setPartGross(

   @ModelAttribute("demoPageForm") DemoPageForm emoPageForm,       

    BindingResult result) {

     .......

     return ... ;

  }

Here the control goes to this controller method.

  • How it is possible ?

  • What is the flow behind this and what is responsible for this mapping ?

    I am using magnolia blossom.

    can anyone suggest.. ?


回答1:


Setting a form action to "?" will make it use the current URL (of the page you are on), and append a querystring "?" to that URL. So if you're on http://example.com/getDemoPage , the form action would be http://example.com/getDemoPage? which is why your Controller responds.

For Spring MVC, you should use Spring's taglib <form:form... to take advantage of automatic HTML escaping (turn this on in web.xml) and CSRF tokens if using Spring Security.

You don't need to set the action on Spring taglib forms, it will always be the current URL. The default method is POST, so you don't need to set that either. Not sure why you have commandName in a regular HTML (non Spring) form, as that's a Spring attribute.



来源:https://stackoverflow.com/questions/29137090/form-action-attribute-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!