Announcement Announcement Module
No announcement yet.
Noob Q: How to perform simple action. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Noob Q: How to perform simple action.

    This should be straight forward, but I'm not sure how to proceed...

    I just want to perform an action in response to a button press - specifically log a user out of the system.

    There's no form, just a link which should log the user out and then send them to the start page. All the Controller classes I can see expect to bind to a bean, validate input etc... SimpleFormController doesn't seem appropriate.

    Would someone mind pointing me in the correct direction?


  • #2
    Ok, so I've done it like this...

    public class LogoutController implements Controller {
        private facade myFacade;
        /** Creates a new instance of LogoutController */
        public LogoutController() {
        public void setFacade(facade value) {
            myFacade= value;
        public facade getFacade() {
            return myFacade;
        public ModelAndView handleRequest(HttpServletRequest request1, HttpServletResponse response2)
            throws Exception {
            //delete the user object from the session.
            return new ModelAndView("welcome");

    Is this the best approach?


    • #3
      A couple of points

      - the constructor you have is not needed, if there are no constructors the jvm will stick one in for you. If you are going to implement a default constructor it is good practice to *always* call super().
      - what is the facade doing? You never seem to use it. Also, all classes in java should start with an upper case character.

      If your *loggedin ness* is by the presence of a session attribute, then yes, what you have written would suffice