我的应用程序服务器是Weblogic 12C,它在apache代理后面工作。
当我通过Spring MVC表单进行GET提交时,值接近后端,但是当我进行POST提交时,所有值在后端都为null。
这是我的文件。
JSP文件
<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
@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>
最佳答案
从此行userForm.getFirstName()
的外观来看,属性firstName,lastName和number似乎是userForm对象的属性,在这种情况下,您的表单应为
<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>
可能会有所不同,具体取决于UserForm类的结构,但是您应该从中获得解决方案的要点