0
我有一個非常簡單的Spring MVC項目:如何在春天MVC結果頁上的URL參數?
@Controller
@RequestMapping("/form.htm")
public class FormController {
FormValidation formValidation;
@Autowired
public FormController(FormValidation formValidation) {
this.formValidation = formValidation;
}
@RequestMapping(method = RequestMethod.GET)
public String initForm(ModelMap model) {
QueryForm queryForm = new QueryForm();
model.addAttribute("queryForm", queryForm);
return "queryForm";
}
@RequestMapping(method = RequestMethod.POST)
public String submitForm(ModelMap model, @ModelAttribute("queryForm")QueryForm queryForm,
BindingResult result) {
List<String> Result = query(queryForm);
SuccessForm successForm = new SuccessForm();
successForm.setId(queryForm.getId());
model.addAttribute("successForm", successForm);
return "successForm";
}
private List<String> query(QueryForm queryForm) {
}
}
的success.jsp:
<head>
<title>deviceInfo display</title>
</head>
<body>
<h1>Id is ${successForm.Id}.</h1>
<br>
<c:forEach var="info" items="${successForm.Info}" >
<p style="font-size:120%"><c:out value="${info}" /></p>
<hr />
</c:forEach>
<br>
</body>
</html>
query.jsp:
<head>
<meta charset="utf-8">
</head>
<body>
<div id="main">
<form class="form" id="queryForm" method="POST" command="queryForm">
<fieldset>
<legend>Please fill in the form</legend>
<p>
<label for="Id" class="sr-only">Id</label>
<input type="text" name="Id" id="Id" class="form-control" placeholder="Id">
</p>
<p>
<button class="btn btn-lg btn-primary btn-block" type="submit">Submit</button>
</p>
</fieldset>
</form>
</div>
</body>
</html>
這樣
,成功的網址。 jsp頁面與query.jsp相同:http://localhost:8080/project/form.htm。我需要在query.jsp上添加一些參數,如:http://localhost:8080/project/form.htm?Id=xxx,所以成功頁面可以發送給其他人,結果存在,我該怎麼做?謝謝。
Spring MVC的版本:2.5.6
謝謝,我可以訪問successForm中的屬性,但我怎樣才能使用它們來生成URL的參數? – nzomkxia