Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7185247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:22:27+00:00 2026-05-28T18:22:27+00:00

I am handling forms in Spring MVC and I submitted a form and I

  • 0

I am handling forms in Spring MVC and I submitted a form and I am trying to redirect the post request to avoid resubmitting the form with refresh button.

But I need a dynamically generated value to be displayed based on the form submission in the redirected page. So I am saving that value in session in the post handler method and getting it back in the redirected page handling method.

Would I get the session attribute shown displayed in the redirected page like request parameters in GET method case?

Following is the code that I am using:

This method is handling the form submission

@RequestMapping(value="/something", method=RequestMethod.POST) 
public String testStopped(Model model, WebRequest request, HttpSession session) {
    //...
    int foo = 1234;//some dynamically generated value
    session.setAttribute("foo", foo);
    return "redirect:/something/somethingelse";
}

This method is handling the redirected page

@RequestMapping(value="/something/somethingelse") 
public String testStopped(Model model, HttpSession session) {
    ...
    Integer kungfoo = (Integer) session.getAttribute("foo");
    model.addAttribute("kungfoo", kungfoo);
    return "somethingelse";
}

This is the url I end up with after redirect: http://wikedlynotsmart.com/something/somethingelse?kungfoo=1234

Is there a way to for ?kungfoo=1234 not to be displayed at the end and still get it passed to the redirect request handler method?

Is this how it is supposed to work or I am committing a blunder somewhere? Could someone help me understand it?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:22:27+00:00Added an answer on May 28, 2026 at 6:22 pm

    Quote from the documentation:

    By default all model attributes are considered to be exposed as URI
    template variables in the redirect URL. Of the remaining attributes
    those that are primitive types or collections/arrays of primitive
    types are automatically appended as query parameters.

    This means that kungfoo is an attribute of your model in the first method, and that it’s thus automatically added as a request param to the redirect URL.

    The rest of the paragraph explains how to proceed if you don’t want all the attributes in the redirect URL (although I have the feeling that the default is exactly what you should use, in this case, since you want the second request to get back the kungfoo value):

    In annotated controllers however the model may contain additional
    attributes originally added for rendering purposes (e.g. drop-down
    field values). To gain precise control over the attributes used in a
    redirect scenario, an @RequestMapping method can declare an argument
    of type RedirectAttributes and use it to add attributes for use in
    RedirectView. If the controller method does redirect, the content of
    RedirectAttributes is used. Otherwise the content of the default Model
    is used.

    If you want to stay with this solution of storing the value in the session, you should use a flash attribute, so it’s removed from the session as soon as the second request is received. The rest of the paragraph explains how to use them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an action handling a form post, but I want to make sure
I was looking at an example at this link http://www.mkyong.com/spring-mvc/spring-mvc-form-handling-annotation-example/ Here the controller class
In handling a form post I have something like public ActionResult Insert() { Order
I am trying to understand architecture of Spring MVC. However, I am completely confused
Just looking at the petclinic sample application, and trying to learn form handling. It
IIS6, ASP.NET 2.0, No Forms Authentication I'm calling Response.Redirect(~/foo.aspx), but the default document (Default.aspx)
I've had troubles for a few days already with handling form that contains dropdown
How would you reccommend handling RSS Feeds in ASP.NET MVC? Using a third party
I have form object that I set to request in GET request handler in
So I recently have been trying to incorporate more sub forms to make the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.