简体   繁体   English

从重定向到JSP到@RequestParam

[英]Redirrect from to JSP to @RequestParam

So I'm having this code in a JSP file: 因此,我在JSP文件中包含以下代码:

<form action="/demo/quests/view?questId=${m.id}" >
    <button type="submit" class="btn btn-primary" >See quest</button>
</form

My method has this definition: 我的方法具有以下定义:

RequestMapping(value = "/view", method = RequestMethod.GET)
public String displayQuest(@RequestParam(value = "questId") String questId, Model model){}

The problem is that my form is redirrecting to quests/view? 问题是我的表单正在重新定向到quests/view? How can I make it redirrect to quests/view?questId=asdasdasd 我如何使其重定向到quests/view?questId=asdasdasd

**Using @requestParam is a must, because with @PathVariable I get a weird bug **必须使用@requestParam,因为使用@PathVariable会出现一个奇怪的错误

Your method definition is ok but you should use your form submission as : 您的方法定义还可以,但是您应该使用以下形式提交表单:

<form action="${pageContext.request.contextPath}/demo/quests/view">
    <input type="text" class="form-control" id="questId" 
    name="questId" required>
    <button type="submit" class="btn btn-primary" >See quest</button>
</form

@RequestParam handles that there is a parameter with name questId which is described at your @RequestParam(value = "questId") method signature. @RequestParam处理有一个名称为questId的参数,该参数在您的@RequestParam(value = "questId")方法签名中进行了描述。 You can check an exact example from my github repo. 您可以从我的github存储库中查看确切的示例。

Form Sample: modalAuthor.jsp#form 表单示例: modalAuthor.jsp#form

Handler Method Sample AuthorController#authorPost 处理程序方法示例 AuthorController#authorPost

Replace 更换

 <form action="/demo/quests/view?questId=${m.id}" >

with

<form action="view?questId=${m.id}" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM