简体   繁体   中英

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. 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. Below i have given the code snippets:

The form that I am sending from the legacy application:

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

The Spring MVC Controller where I have defined the method to retrieve the form data:

@RequestMapping(value = "/" , method = RequestMethod.POST)
    public String getMethod(@RequestParam String id ,ModelMap model, HttpServletRequest request){

         model.addAttribute("login", id);
         return "index";
    }

The error i am getting in firebug:

在此处输入图片说明

您不是从表单发送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'.

Rename the method parameter to 'login' or qualify it by specifying the HTTP param name:

@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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM