how to create a cookie and add to http response from inside my service layer?

前端 未结 4 848
天涯浪人
天涯浪人 2021-01-03 21:25

I am creating a custom authentication service in my spring mvc application:

@Service
public class AuthenticationServiceImpl implements AuthenticationService          


        
4条回答
  •  盖世英雄少女心
    2021-01-03 22:04

    In Spring MVC you get the HtppServletResponce object by default .

       @RequestMapping("/myPath.htm")
        public ModelAndView add(HttpServletRequest request,
             HttpServletResponse response) throws Exception{
                //Do service call passing the response
        return new ModelAndView("CustomerAddView");
        }
    
    //Service code
    Cookie myCookie =
      new Cookie("name", "val");
      response.addCookie(myCookie);
    

提交回复
热议问题