简体   繁体   English

无法在Spring应用程序中接收其他Java应用程序发送的表单数据

[英]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: 下面我给出了代码片段:

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: 我在其中定义了检索表单数据的方法的Spring MVC Controller:

@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'. 您正在发送一个名为“ 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.

相关问题 Dart - 如何接收和解码从Java应用程序发送的JSON数据包 - Dart - How to receive and decode JSON packet sent from a Java application 如何在 Angular/Spring Boot 应用程序中接收服务器端的表单数据? - How to receive form data on the server side in an Angular/Spring Boot application? Java侦听器,用于从手机发送到Java应用程序的数据 - Java Listener for data sent from my mobile to a java application 将数据从一个Java应用程序发送到另一个 - Send data from one Java application to another Java Spring 引导应用程序无法从 json 文件中提取数据 - Java Spring Boots Application Not able to extract data form json file 当表单数据请求发送到 Spring 引导应用程序时,LocalDate 属性上的转换错误 - Conversion Error on LocalDate attribute when form-data request is sent to a Spring boot application 从另一个Java应用程序启动Java应用程序 - Launch a java application from another java application 从另一个Java应用程序控制Java应用程序 - Control java application from another java application 无法将 Spring Boot 应用程序部署到另一个虚拟机 - Cannot deploy spring boot application to another vm 从另一个Java应用程序运行桌面应用程序 - running a desktop application from another java application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM