2

I am having a form which submits new articles to my controller.

JSP Page:

<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>

Controller Method:

@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
}

Now from the above controller method I wanna redirect to another method where I want to pass currently saved article id as http://<myurl>/article?articleId="xyz".

Here is my get method code for handling the redirect.

@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;
} 

I wanna know how could I access that passed request parameter in above method?

4

3 回答 3

1

如果您提交不带参数的操作 url,或者hidden为此目的使用字段,那么您应该将该参数作为结果返回。因此,您不会丢失它,或重定向到不再需要该参数的页面。要在 url 中传递参数,请使用

<form class="form-signin" method="post" action="/articleViewer?varArticleID=94"> 
于 2013-06-30T14:01:17.570 回答
1

我通过使用 Redirect 属性来解决它作为回报......

return "redirect:/articleViewer?varArticleID="+getVarArticleID();
于 2013-07-01T02:39:22.953 回答
0

因此,如果您需要提交后的页面,请更改表单的操作值,例如

<form class="form-signin" method="post"
    action="/articleViewer?varArticleID={yourArticleid}">

提交后您还需要

return Path.Jsp.ARTICLE_VIEWER_PAGE+"?varArticleID="+request.getParameter("varArticleID");
于 2013-06-30T13:47:43.710 回答