Cannot receive form data in Spring application sent from another java application

北城余情 提交于 2019-12-12 03:25:34

问题


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:


回答1:


You're not sending the id param from the form, so inside your form you're missing something like

 <input type="hidden" name="id" value='[SOME VALUE]'>



回答2:


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



来源:https://stackoverflow.com/questions/27549051/cannot-receive-form-data-in-spring-application-sent-from-another-java-applicatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!