What I need is to redirect a User to a new "home page" with data taken from form input that the user would have entered before clicking the submit
button.
我需要的是将用户重定向到一个新的“主页”,其中包含从用户在单击提交按钮之前输入的表单输入中获取的数据。
For example (but not what is exactly required): if a form asks the user Bob to enter data about himself, when Bob submits the form he will be taken to a new formatted page example.com/bob
with all the information he entered.
例如(但不是确切要求的):如果表单要求用户Bob输入关于他自己的数据,当Bob提交表单时,他将被带到新的格式化页面example.com/bob,其中包含他输入的所有信息。
A new jsp page would not be created, but somehow I need the controller to take the url and search the database for the user "Bob" and format the directed page with all Bob's information.
将不会创建新的jsp页面,但不知何故,我需要控制器获取URL并在数据库中搜索用户“Bob”并使用所有Bob的信息格式化定向页面。
2 个解决方案
#1
1
You can use a url like example.com/bob
using path variables.
您可以使用路径变量之类的url,例如example.com/bob。
In your controller you need something like this:
在你的控制器中你需要这样的东西:
@RequestMapping("/{name}")
public String userDetails(@PathVariable String name){
// retrieve user details from DB by username
return "redirect:/" + name;
}
Take a look at Spring MVC docs.
看一下Spring MVC文档。
#2
1
User userFind = userMetier.getUserByEmail(user.getEmail);
Return "home2.html?name="+userFind.getName()+"?email="+userFind.getEmail() ;
#1
1
You can use a url like example.com/bob
using path variables.
您可以使用路径变量之类的url,例如example.com/bob。
In your controller you need something like this:
在你的控制器中你需要这样的东西:
@RequestMapping("/{name}")
public String userDetails(@PathVariable String name){
// retrieve user details from DB by username
return "redirect:/" + name;
}
Take a look at Spring MVC docs.
看一下Spring MVC文档。
#2
1
User userFind = userMetier.getUserByEmail(user.getEmail);
Return "home2.html?name="+userFind.getName()+"?email="+userFind.getEmail() ;