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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:17:11+00:00 2026-06-14T22:17:11+00:00

I have a Spring MVC 3 application where we have two pages. One page

  • 0

I have a Spring MVC 3 application where we have two pages. One page users select some data, which is posted to the controller and buildsup page 2. Then after page 2 gets its values, I want to use the values of the firstpage for the database action.

Things I’ve tried so far:

I looked at the ModelAttribute

First up is the post of the first controller:

@RequestMapping(value = "/firstPage")
public ModelAndView firstPageSubmit(String valuePage1, String valuePage2) {
     return new ModelAndView("secondPage", "readonlySettings", new ReadonlySettings( valuePage1, valuePage2 );
} 

And I was hoping, spring would preserve this object, and give it to me again:

@RequestMapping(value = "/secondPage")
public ModelAndView secondPage(@ModelAttribute("readonlySettings") ReadonlySettings settings, String valuePage2) {
     //Store stuff in the database
     doa.save(settings.getValuePage1(), settings.getValuePage2(), valuePage2);
} 

But no dice.. All the values are empty.

Btw: I did nothing with the ReadonlySettings object on the jsp itself. So no hidden fields or whatever, because I do not like this solution. People can change hidden fields, and that is something I really wish to avoid.

Does anyone know how to handle this?

  • 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-06-14T22:17:13+00:00Added an answer on June 14, 2026 at 10:17 pm

    You can tell Spring to keep the object around associated with the user’s web session on the server side by using @SessionAttributes.

    @Controller
    @SessionAttributes("readonlySettings")
    public class MyController {
    
    @RequestMapping(value = "/firstPage")
    public ModelAndView firstPageSubmit(String valuePage1, String valuePage2, ModelMap map) {
        map.addAttribute("readonlySettings", new ReadonlySettings( valuePage1, valuePage2 );
        return new ModelAndView("secondPage");
    } 
    
    @RequestMapping(value = "/secondPage")
    public ModelAndView secondPage(ModelMap map, SessionStatus status, String valuePage2, ) {
        ReadonlySettings settings = map.getAttribute("readonlySettings");
        doa.save(settings.getValuePage1(), settings.getValuePage2(), valuePage2);
        status.setComplete();
    } 
    

    Now obviously this is fairly primitive. Depending on the context of the operation you may need to add handling for when someone loads the second page directly via a link and has no object in their session. Also the object will be left hanging there until the session is cleaned up if someone never completes the second step. (May be tolerable in the case of just two strings.) If your actual use case is significantly more complicated than this, you may want to look in to something like web flow rather than re-inventing.

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

Sidebar

Related Questions

I have two request mappings in a Spring MVC 3 application, one which takes
I am preparing a registration page using JSF/Spring webflow&mvc application. I have added two
I have two Spring contexts declared in my application - one for Spring-MVC requests,
I have a Spring MVC application which uses FreeMarker as View technology (But maybe
I have a ASP.Net MVC application which serves user pages with URL like -
I have a Spring MVC application which has a public front-end WAR, an admin
I have a fairly simple data audit web application written with ASP MVC which
I have a Spring MVC application which communicates with the frontend with AJAX /
I have two class definitions in my Spring MVC web application named Class and
I have an application which are using Hibernate / Spring and Spring MVC, but

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.