Search code examples
spring-mvcjstl

Displaying message on jsp page in spring mvc application


This my Controller where I am returning variable in ModelMap attribute to that same jsp page if successful or failure

 @RequestMapping(value="/SChangePassUpdate",method=RequestMethod.POST)
        public ModelAndView PassChangeStaff(@RequestParam("OldPassword")String oldpass,
                                 @RequestParam("NewPassword")String newpass,
                                 @RequestParam("ConfirmNewPassword")String cnfpass,ModelMap map){

        String sid=session.getAttribute("StaffLoggedIN").toString();
        boolean result=staffservice.changepass(sid,oldpass,newpass,cnfpass);
        if(result){
            map.addAttribute("message", "Password changed successfully");
        return new ModelAndView("StaffChangePass",map);
        }else{
            map.addAttribute("message", "Password changed failure");
            return new ModelAndView("StaffChangePass",map);
        }
    }

In jsp I did this

 <c:if test="${not empty message}">
          <p id="panel">${message}</p>
      </c:if>

panel taken as id is similar to Toast Message in android more appropriately jquery animation since I want this to animate only if variable is not empty but the password changes and nothing is displayed.


Solution

  • It should work ideally but just to troubleshoot can you please print the value of message outside if condition like this :

    <c:out = "${message}"/>
    

    And based on this put your condition.

    Hope it helps..!!