【发布时间】:2013-06-27 18:26:25
【问题描述】:
我有一个向我的控制器提交新文章的表单。
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为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中的一个重要参数。
-
是的,提交表单后我丢失了参数,它显示页面空白 bcz 它需要 ArticleID 作为输入参数
-
对,你没发jsp,没法回答。
-
这在意料之中。 Post 参数在请求正文中发送,而不是在查询字符串中。您应该保存评论,然后重定向。见en.wikipedia.org/wiki/Post/Redirect/Get
-
不要在 cmets 中发布代码。编辑您的问题。
标签: java spring jsp spring-mvc url-parameters