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 3697310
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:50:40+00:00 2026-05-19T04:50:40+00:00

I currently would like to expand my knowledge on Spring MVC so I am

  • 0

I currently would like to expand my knowledge on Spring MVC so I am investigating the sample web apps that the spring distribution has. I am basically checking the Petclinic application.

In the GET method, the Pet object was added into the model attributes so the JSP can access the javabean properties. I think I understand this one.

@Controller
@RequestMapping("/addPet.do")
@SessionAttributes("pet")
public class AddPetForm {
    @RequestMapping(method = RequestMethod.GET)
    public String setupForm(@RequestParam("ownerId") int ownerId, Model model) {
        Owner owner = this.clinic.loadOwner(ownerId);
        Pet pet = new Pet();
        owner.addPet(pet);
        model.addAttribute("pet", pet);
        return "petForm";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) {
        new PetValidator().validate(pet, result);
        if (result.hasErrors()) {
            return "petForm";
        }
        else {
            this.clinic.storePet(pet);
            status.setComplete();
            return "redirect:owner.do?ownerId=" + pet.getOwner().getId();
        }
    }
}

But the thing that I cannot understand is during the POST operation. I look up at my firebug, and I notice that my post data are only the data that was entered by the user which to me is fine.

alt text

But when I inspect the data on my controller. The owner info is still complete. I look up at the generated HTML from the JSP but I cannot see some hidden information about the Owner object. I am quite not sure where does Spring gather the info on the owner object.

Does this mean that Spring is caching the model objects per each thread request?

alt text

This is for Spring MVC 2.5.

  • 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-19T04:50:40+00:00Added an answer on May 19, 2026 at 4:50 am

    The key to this behavior is @SessionAttributes("pet") which means that the pet attribute of the model will be persisted in the session. In setupForm you perform the following operations:

        Pet pet = new Pet();
        owner.addPet(pet);
        model.addAttribute("pet", pet);
    

    Which means: create an Pet object, add it to the owner specified in the request (@RequestParam("ownerId") int ownerId), this is probably where the pet owner attribute gets set.

    In the processSubmit method, you declare @ModelAttribute("pet") Pet pet in the method signature which means that you want the Pet object you previously store in the session. Spring retrieves this object and then merge it with whatever had been set in the JSP. Hence a filled owner id.

    More information in the Spring documentation

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

Sidebar

Related Questions

I'm working on a project that currently has zero users but we would like
I would like to find out, in JavaScript, which element currently has focus. I've
I would like to see the threads currently active in my application while debugging
Our customer would like to know who is online and currently using the custom
I would like to add an operator to a class. I currently have a
I currently have a controller were I would like to keep track of logging
I'm currently building a project and I would like to make use of some
I currently have a small Java program which I would like to run both
Currently I have a ListView (using the Details View). I would like to implement
I am currently working on a REST library for .net, and I would like

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.