如何将 RequestParam 值作为 URL [英] How to put RequestParam value as URL

查看:15
本文介绍了如何将 RequestParam 值作为 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jsp页面中有一些输入字段,我想知道这些字段中传递的值是否可以作为URL传递.

I have some input fields in my jsp page,l want to know is it possible for values passed in those fields to be passed as URL.

我尝试在同一个变量上使用 @RequestParam 和 @PathVariable 来尝试检索它并将其作为 URI,但它没有用

I tried using @RequestParam and @PathVariable on same variable to try to retrive it and put it as URI but it didnt work

这是我的jsp页面表单:

This is my jsp page form:

<body>
 <form action="welcome/" method="post">
  <input type="text" name="name" value="">
  <input type="submit"  value="go">
 </form>
</body>

这是我的控制器处理程序方法:

And this is my Controller handler method:

@PostMapping(value = "/welcome/{name}")
public String welcomeAgain(@PathVariable @RequestParam("name")String name){
    return "welcome";
}

推荐答案

要获取传入 URL 的值,您可以使用 @PathVariable 通常和 GET 请求.

To get the value passed in URL you can use @PathVariable normally with GET request.

http://localhost:8080/user/101

@RequestParam 通常与 POST 请求一起使用,用于访问查询参数值

@RequestParam normally used with POST request for accessing the query parameter values

http://localhost:8080/user/101?param1=10&param2=20

<小时>

@PostMapping(value = "/welcome/{name}")
public String welcomeAgain(@PathVariable("name") String name){
    return "welcome " + name;
}

这篇关于如何将 RequestParam 值作为 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆