1

In my web application, I want to implement a system for displaying info/error messages when it is needed. For example, servlet detects some error (e.g. user is not logged in), adds custom error message to session and redirects the user to login page, the JSP responsible for displaying the login page also displays that message. Another example, user submits some form successfully, servlet adds custom success message and redirects to some page wherein the success message is displayed.

My implementation proposal: servlet writes message in session and a special included JSP on any page will read it, display it and remove it from session (so it is displayed only once). I need to have it in session, because the message would otherwise not be preserved across a redirect.

Form the logic and MVC point of view, is it ok to remove the variable with message in JSP?

manlio
  • 18,345
  • 14
  • 76
  • 126
betatester07
  • 667
  • 8
  • 16

1 Answers1

0

If it's possible with JSTL, then it should be no big deal.

And it is:

<c:remove var="message" scope="session" />

Note that some MVC frameworks solve this with help of a cookie which is also known as "flash scope". See also e.g. this answer in context of Java EE's own MVC framework JSF.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555