Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 将post变量传递给另一个方法_Spring_Variables_Post_Get - Fatal编程技术网

Spring 将post变量传递给另一个方法

Spring 将post变量传递给另一个方法,spring,variables,post,get,Spring,Variables,Post,Get,我有这样的代码 @RequestMapping(value=“/persons”,method=RequestMethod.POST) public@ResponseBody String addUser(@RequestParam String name){ returnText=name; //List personList=personService.getAllzonedetails(返回文本); System.out.println(returnText); //addAttribut

我有这样的代码

@RequestMapping(value=“/persons”,method=RequestMethod.POST) public@ResponseBody String addUser(@RequestParam String name){

returnText=name;
//List personList=personService.getAllzonedetails(返回文本);
System.out.println(returnText);
//addAttribute(“personsajax”,personList);
返回**返回文本**;
}

@RequestMapping(value=“/persons”,method=RequestMethod.GET)
公共字符串getPersons(模型){
newvariable=返回文本;
System.out.println(新变量);
logger.debug(“收到显示所有人员的请求”);
//通过将调用委派给PersonService来检索所有人员
List persons=personService.getAll();
List persons1=personService.getAllzonedetails(新变量);
//将人员附加到模型上
模型。添加属性(“人员”,人员);
addAttribute(“personsajax”,persons1);
//这将解析为/WEB-INF/jsp/PersonPage.jsp
返回“个人主页”;
}
我想在System.out.println(newvariable)中获取returnText post值;在get方法中传递jsp页面

在jsp中传递post值的任何其他方法


谢谢…

我认为您要做的是,当用户添加到post方法中时,您希望重定向到GET方法,并在人员列表页面上显示新添加的用户名

你在这里试过的不合适。首先,您需要更改POST方法中的@ResponseBody注释,并从该函数返回“redirect:/persons”字符串。这将重定向到GET方法。现在,要在GET方法中使用新添加的用户名,需要使用RedirectAttributes将用户名返回给GET方法

为此,在post方法签名中再添加一个参数,
RedirectAttributes-RedirectAttributes
。然后在return语句之前插入下一行

redirectAttributes.addFlashAttribute("newUserName", returnText);
然后可以使用EL
${newUserName}
访问JSP中的值

我希望这对你有帮助

@RequestMapping(value = "/persons", method = RequestMethod.GET)
public String getPersons(Model model) {

    newvariable = returnText;
    System.out.println(newvariable); 
 logger.debug("Received request to show all persons");
 // Retrieve all persons by delegating the call to PersonService
 List<Person> persons = personService.getAll();
 List<Person> persons1 = personService.getAllzonedetails(newvariable);
     // Attach persons to the Model
 model.addAttribute("persons", persons);
 model.addAttribute("personsajax", persons1);
 // This will resolve to /WEB-INF/jsp/personspage.jsp
 return "personspage";
}
redirectAttributes.addFlashAttribute("newUserName", returnText);