问题
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