[英]Cannot receive form data in Spring application sent from another java application
I am trying to post an HTML form from a legacy java application to a Spring based java application.But the form field cannot be received there. 我正在尝试将HTML表单从旧版Java应用程序发布到基于Spring的Java应用程序中。但是在此处无法接收到表单字段。 can you please help on how to resolve the issue. 您能帮忙解决此问题吗? Note: I am posting the form from tomcat 5.5 to the new Spring application in tomcat 6 though Both the containers reside in the same server. 注意:我将表单从tomcat 5.5发布到tomcat 6中的新Spring应用程序,尽管这两个容器都位于同一服务器中。 Below i have given the code snippets: 下面我给出了代码片段:
<form id ="user_Spring" method="POST" action="http://new_application_url/app-root/" ENCTYPE="application/x-www-form-urlencoded">
<input type="hidden" name="login" value='<%=user_Login %>'>
</form>
<a href="#" onclick="document.getElementById('user_Spring').submit();"><font color="red"></>New Application</font></a> |
@RequestMapping(value = "/" , method = RequestMethod.POST)
public String getMethod(@RequestParam String id ,ModelMap model, HttpServletRequest request){
model.addAttribute("login", id);
return "index";
}
您不是从表单发送id参数,因此在表单内部您缺少诸如
<input type="hidden" name="id" value='[SOME VALUE]'>
You are sending a form parameter named 'login' but you expect it to be magically bound to a method param named 'id'. 您正在发送一个名为“ login”的表单参数,但是您希望它神奇地绑定到一个名为“ id”的方法参数上。
Rename the method parameter to 'login' or qualify it by specifying the HTTP param name: 将方法参数重命名为'login'或通过指定HTTP参数名称对其进行限定:
@RequestMapping(value = "/" , method = RequestMethod.POST)
public String getMethod(@RequestParam("login") String id ,ModelMap model, HttpServletRequest request){
model.addAttribute("login", id);
return "index";
}
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestparam http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-ann-requestparam
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.