我有一種向我的控制器提交新文章的表單。無法訪問SpringMVC控制器中的請求參數,同時重定向到URL
JSP頁面:
<form class="form-signin" method="post"
action="/articleViewer">
<div class="control-group" style="margin-top: -5px;">
<label class="control-label text-info" for="commentContent"><strong>Post
Comment</strong></label>
<div class="controls">
<textarea class="FormElement" name="area2" id="commentContent"
style="width: 100%;"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary" style="margin-left: 90%;">Post</button>
</form>
控制器的方法:
@RequestMapping(value="/articleViewer", method = RequestMethod.POST)
public String saveArticleComment (HttpServletRequest request, HttpServletResponse response,Principal principal, ModelMap map) throws ServletException, IOException{
//processing request
System.out.println("Link : "+Path.Jsp.ARTICLE_VIEWER_PAGE);
return Path.Jsp.ARTICLE_VIEWER_PAGE; //this ARTICLE_VIEWER_PAGE = /articleViewer
}
從上面的控制器方法我想重定向到哪裏我想通過 目前保存的物品ID的另一種方法
現在as http://<myurl>/article?articleId="xyz".
這是我處理重定向的get方法代碼。
@RequestMapping(value="/articleViewer", method= RequestMethod.GET)
public String articleViewer(HttpServletRequest request, Principal principal,
ModelMap map, HttpServletResponse response)
throws DatabaseException {
//I wanna access article id here.
return Path.Jsp.ARTICLE_VIEWER_PAGE;
}
我想知道如何訪問上面的方法中傳遞的請求參數?
這意味着你在失去URL一個重要的參數。 –
Yess提交表單後,我失去了參數,它顯示頁面bloank bcz需要以ArticleID作爲輸入參數 – Complicated
是的,您沒有發佈jsp,無法回答。 –