My app server is Weblogic 12C and it is working behind an apache proxy.
When I was doing GET submit through the spring MVC form, values are coming to back end, but when I was doing a POST submit, all values comes as null at the backend.
Here is my files.
JSP File
<form:form method="post" modelAttribute="userForm" action="createUser">
<form:input path="userInfo.number" readonly="true" maxlength="100"/>
<form:input path="userInfo.firstName" readonly="true" maxlength="500"/>
<form:input path="userInfo.lastName" readonly="true" maxlength="500"/>
<input type="submit" style="font-weight: bold;" value="Send"></td>
</form:form>
Controller
@Controller
@RequestMapping(value = "/")
@SessionAttributes("user")
public class TestController {
@RequestMapping(method = RequestMethod.POST, value="createUser")
public String createUser(@Valid UserForm userForm,BindingResult result,ModelMap modelMap) {
LOGGER.debug("Handling POST description" + userForm.getFirstName());
}
}
web.xml
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>userFormServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-beans/servlet-context.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>userFormServlet</servlet-name>
<url-pattern>/apps/*</url-pattern>
</servlet-mapping>
By the looks of this line userForm.getFirstName()
, it seems that the properties firstName , lastName and number are the properties of the userForm object, in that case your form should be
<form:form method="post" modelAttribute="userForm" action="createUser">
<form:input path="number" readonly="true" maxlength="100"/>
<form:input path="firstName" readonly="true" maxlength="500"/>
<form:input path="lastName" readonly="true" maxlength="500"/>
<input type="submit" style="font-weight: bold;" value="Send"></td>
</form:form>
maybe slightly different depending on the structure of your UserForm class, but you should get a gist of a solution from this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.