SpringMVC FormTag resolve action

 1 /**
 2      * Resolve the value of the ‘<code>action</code>‘ attribute.
 3      * <p>If the user configured an ‘<code>action</code>‘ value then
 4      * the result of evaluating this value is used. Otherwise, the
 5      * {@link org.springframework.web.servlet.support.RequestContext#getRequestUri() originating URI}
 6      * is used.
 7      * @return the value that is to be used for the ‘<code>action</code>‘ attribute
 8      */
 9     protected String resolveAction() throws JspException {
10         String action = getAction();
11         if (StringUtils.hasText(action)) {
12             action = getDisplayString(evaluate(ACTION_ATTRIBUTE, action));
13             return processAction(action);
14         }
15         else {
16             String requestUri = getRequestContext().getRequestUri();
17             ServletResponse response = this.pageContext.getResponse();
18             if (response instanceof HttpServletResponse) {
19                 requestUri = ((HttpServletResponse) response).encodeURL(requestUri);
20                 String queryString = getRequestContext().getQueryString();
21                 if (StringUtils.hasText(queryString)) {
22                     requestUri += "?" + HtmlUtils.htmlEscape(queryString);
23                 }
24             }
25             if (StringUtils.hasText(requestUri)) {
26                 return processAction(requestUri);
27             }
28             else {
29                 throw new IllegalArgumentException("Attribute ‘action‘ is required. " +
30                         "Attempted to resolve against current request URI but request URI was null.");
31             }
32         }
33     }

源码注释中写到,如果页面<form:form action="" method="POST">,如果action为空,则根据 getRequestUri()来设置action。

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。