0
我有兩個頁面:一個搜索頁面和一個編輯頁面(jsp文件)。搜索頁面用於搜索和顯示項目列表。編輯頁面用於編輯項目。重定向到更新的頁面
在搜索頁面中,我有一個項目編號的鏈接,用於導航到編輯頁面。
當用戶成功編輯項目時,他們將被重定向到搜索頁面。
我的問題是如何使搜索頁面立即顯示最新的項目,而無需刷新或搜索?我使用hibernate + spring mvc。
在此先感謝您的幫助!
我有兩個頁面:一個搜索頁面和一個編輯頁面(jsp文件)。搜索頁面用於搜索和顯示項目列表。編輯頁面用於編輯項目。重定向到更新的頁面
在搜索頁面中,我有一個項目編號的鏈接,用於導航到編輯頁面。
當用戶成功編輯項目時,他們將被重定向到搜索頁面。
我的問題是如何使搜索頁面立即顯示最新的項目,而無需刷新或搜索?我使用hibernate + spring mvc。
在此先感謝您的幫助!
我認爲它做的工作。通過會話將搜索模式傳遞給編輯操作。因此,您可以在重定向到搜索頁面時顯示更新後的搜索結果。
@Controller
public class ProjectsController {
@RequestMapping(value = "edit", method = RequestMethod.POST)
String doEditProject(HttpSession httpSession, @ModelAttribute Project p) {
// persist the edited project
// redirect to search page with last search word
String searchPattern = (String) httpSession.getAttribute("search_pattern");
return "redirect:search?pattern=" + searchPattern;
}
@RequestMapping(value = "search", method = RequestMethod.GET)
String displaySearch(@RequestParam(value = "pattern", required = false) String searchPattern, ModelMap model, HttpSession httpSession) {
if (searchPattern == null) {
// display empty search view
return "searchView";
} else {
// search using the pattern
// put model and create links like edit?project_id=xx
httpSession.setAttribute("search_pattern", searchPattern);
return "searchView";
}
}
}
到目前爲止,如果你經歷了幾個教程,你應該弄清楚什麼? – Shahzeb
您的問題描述缺少關於您的UI應該如何工作的重要信息。什麼需要刷新?搜索表單?搜索結果? –
你使用註釋基地春天mvc? –