嗨,我有一个问题,我正在学习如何用PathVariable传递值,我有一个带有输入文本和按钮的表单,当你按下按钮时,它会带你到另一个页面并显示这个值,但是当我按下这个按钮时,它就不起作用了。它带我到这个网址:
http://localhost:8080/appThyme/shoForm1.html?firstname=MyName&submit=
我得到了一个错误HTTP 404 - /appThyme/showForm1.html
但是,如果我把这个URL:http://localhost:8080/appThyme/respuesta/Myname工作它显示给我我的页面上有我的名字,我怎样才能让它只按下按钮,为什么当我按这个按钮时,它会给我的URI添加问号和相等的符号
@Controller
public class HomeController {
@RequestMapping(value = "/form1", method = RequestMethod.GET)
public String showFormulario2(Model model) {
logger.info("***PAG formulario***");
return "form1.html";
}
@RequestMapping(value = "/showForm1/{id}", method = RequestMethod.GET)
public String showForm(Model model, @PathVariable("id") String id)
{
String theId= id;
model.addAttribute("TheID", theId);
return "showForm1.html";
}我的form1.html页面
<form id="guestForm" th:action="@{/showForm1.html}" method="get">
<div>
<input type="text" name="firstname" id="firstname"></input>
</div>
<div>
<button type="submit" name="submit">Submit</button>
</div>
</form>我的howForm1.html页面
enter code here
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The value is ${nombre} </P>
</body>
</html>发布于 2014-09-03 15:57:13
表单提交并不打算使用您在这里使用的@PathVariable构造。@PathVariable用于REST风格的URI,而这不是在表单提交上生成的。
如果您将控制器签名更改为如下所示:
@RequestMapping("/showForm1.html", method = RequestMethod.GET)
public String showForm(Model model, @RequestParam("firstname") String id)
{
String theId= id;
model.addAttribute("TheID", theId);
return "showForm1.html";
}然后,在表单提交时应该正确地调用该方法。
https://stackoverflow.com/questions/25648446
复制相似问题