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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:23:56+00:00 2026-06-05T00:23:56+00:00

I have a spring controller UserController and I have the following methods (business logic

  • 0

I have a spring controller UserController and I have the following methods (business logic not included):

    @RequestMapping(value = "new", method = RequestMethod.GET)
public String getNewUserForm(Model model) {
    model.addAttribute("action", "Create");
    model.addAttribute(new User());
    return "users/edit";
}

@RequestMapping(value = "create", method = RequestMethod.POST)
public String getCreateUser(@ModelAttribute("user") User user, BindingResult result, RedirectAttributes attr) {
    attr.addFlashAttribute("user", user);
    return "redirect:view";
}

@RequestMapping(value = "view", method = RequestMethod.GET)
public String getViewUser(Model model) {
    return "users/view";
}

I end up with three “actions” (new, create, and view). What I want to achieve is the following: app.com/users/new is entered in the browser. The create user form users/edit is displayed. When the form is submitted, it calls users/create (POST). When the user is created successfully, I would like to forward the user to users/view, and display the input data in a non-editable page. I can’t just return view because then the url remains app.com/users/create. I’d like for it to read app.com/users/view.

Right now, I’m using a RedirectAttributes object, combined with returning redirect:view and it works. But it feels like there should be a better way to accomplish this. I tried using redirect:view without RedirectAttributes and the model wasn’t available.

The other alternative is to pass the user id in the url (for example: app.com/users/view/1) and load up the data from the database. But that seems like an unnecessary round trip to the database, considering I already have the latest version of the object. I will be implementing this for “pretty urls”, but I wan’t to have the option to not load the user object if it’s available.

Something like this:

    @RequestMapping(value = "view", method = RequestMethod.GET)
public String getViewUser(Model model, @RequestParam(required = false) String id) {

    if(!model.containsAttribute("user")){
        //get it from the db with the optional request parameter
    }

    return "users/view";
}

Is my approach recommended? Or am I looking at this completely wrong?

  • 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-05T00:23:58+00:00Added an answer on June 5, 2026 at 12:23 am

    The better way is to redirect to app.com/users/view/1.

    First because you have the latest changes you did to the model, but not the ones another concurrent user might have done concurrently.

    Second because it makes your app stateless, thus more scalable and simpler at the same time.

    Third because the view page might need more information about the user than the edit page does. It’s pretty frequent to have a large detail page showing many associations of the user, but have only some modifiable information in the edit page. So saving the model of the edit page to make it available to the view page won’t be sufficient.

    Fourth because this way, the logic to show the detail of a user is at a single place, and there is only one possible URL to do that.

    Fifth because this way, the user can bookmark the URL, or send it to someone by email, and it will work if he comes back later to this URL. Whereas in your current solution, the URL only works if you’ve edited the user just before.

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

Sidebar

Related Questions

I have the following Spring Controller @Controller @RequestMapping(/accreq) with the following mapping @RequestMapping(value =
If I have a RequestMapping in a Spring controller like so... @RequestMapping(method = RequestMethod.GET,
I currently have a Spring MVC controller that takes a MultipartFile @RequestMapping(method = RequestMethod.POST)
I have a spring controller defined like this: @Controller @RequestMapping(/user) class UserController { ...
First I have a Spring 3.0 controller with a method similar to the following.
I have a spring mvc controller that returns a pojo : @RequestMapping(value = /person,
If I have a Spring Controller with two SEPARATE methods, one annotated by: @ExceptionHandler(Exception.class)
I'm facing following problem actually: I'm using Spring with jQuery. I have Controller: @Controller
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
I have a controller with two simple Methods: UserController Methods: [AcceptVerbs(HttpVerbs.Get)] public ActionResult Details(string

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.