Y
Y
Yuri2017-01-20 10:39:53
Java
Yuri, 2017-01-20 10:39:53

How to display user data in JSP?

There is a webapp with user registration through Spring Security. How to pass user data from database to JSP? Or from a java object to a JSP.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
al_gon, 2017-01-20
@MoonMay

@RequestMapping(value = { "/", "/welcome" }, method = RequestMethod.GET)
  public String welcome(Model model) {

    User user = authorizedUser.getUserByUsername();
    System.err.println("Отработал контроллер /welcome  Name: " + user.getUsername() + " Email: " + user.getEmail()
        + " Password: " + user.getPassword());
    model.addAttribute("user", user);

    return "welcome";
  }

In JSP ${user.name}
PS: Didn't check the code!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question