將這些參數從一個jsp頁面傳遞到另一個頁面的最佳方式是什麼?如何將多個參數從一個視圖傳遞到另一個視圖(Spring MVC)
首先處理方法:
@RequestMapping(value="/search", method = RequestMethod.POST)
public String postSearchStudent(
@RequestParam(value = "program.programId") String programId,
@RequestParam(value = "rollNumber") String rollNumber,
@RequestParam(value = "rollYear") String rollYear,
@RequestParam(value = "indexNumber") String indexNumber,
Model model) {
// do something ???
// Call StudentService to do the searching
Student student = studentService.search(indexNumber);
// if student isn't in the db load addStudent.jsp, else load student.jsp
if (student == null)
return "addStudent";
else
return "student";
}
searchStudent.jsp:
<c:url var="searchUrl" value="/essays/main/student/search" />
<form:form modelAttribute="student" method="POST" action="${searchUrl}">
第二處理程序方法:
@RequestMapping(value="/add", method = RequestMethod.GET)
public String getAddStudent(
@RequestParam(value = "program.programId") String programId,
@RequestParam(value = "rollNumber") String rollNumber,
@RequestParam(value = "rollYear") String rollYear,
@RequestParam(value = "indexNumber") String indexNumber,
Model model) {
Student student = new Student();
student.setRollNumber(rollNumber);
student.setRollYear(rollYear);
student.setIndexNumber(indexNumber);
Program program = programService.get(programId);
student.setProgram(program);
model.addAttribute("student", student);
return "addStudent";
}
addStudent.jsp:
<c:url var="saveUrl" value="/essays/main/student/add" />
<form:form commandName="student" method="POST" action="${saveUrl}">
誰能告訴我如何將這4個參數(programId,rollNumber,rollYear,indexNumber)從searchStudent.jsp傳遞給addStudent.jsp?
和你在'getAddStudent()'方法中做的一樣... – zeroflagL