下面列出了怎么用org.springframework.web.servlet.ModelAndViewDefiningException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 세션에 계정정보(LoginVO)가 있는지 여부로 인증 여부를 체크한다.
* 계정정보(LoginVO)가 없다면, 로그인 페이지로 이동한다.
*/
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
boolean isPermittedURL = false;
LoginVO loginVO = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();
if(loginVO != null){
return true;
} else if(!isPermittedURL){
ModelAndView modelAndView = new ModelAndView("redirect:/uat/uia/egovLoginUsr.do");
throw new ModelAndViewDefiningException(modelAndView);
}else{
return true;
}
}
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession");
if (userSession == null) {
String url = request.getServletPath();
String query = request.getQueryString();
ModelAndView modelAndView = new ModelAndView("SignonForm");
if (query != null) {
modelAndView.addObject("signonForwardAction", url+"?"+query);
}
else {
modelAndView.addObject("signonForwardAction", url);
}
throw new ModelAndViewDefiningException(modelAndView);
}
else {
return true;
}
}
protected Object formBackingObject(HttpServletRequest request) throws ModelAndViewDefiningException {
UserSession userSession = (UserSession) request.getSession().getAttribute("userSession");
Cart cart = (Cart) request.getSession().getAttribute("sessionCart");
if (cart != null) {
// Re-read account from DB at team's request.
Account account = this.petStore.getAccount(userSession.getAccount().getUsername());
OrderForm orderForm = new OrderForm();
orderForm.getOrder().initOrder(account, cart);
return orderForm;
}
else {
ModelAndView modelAndView = new ModelAndView("Error");
modelAndView.addObject("message", "An order could not be created because a cart could not be found.");
throw new ModelAndViewDefiningException(modelAndView);
}
}
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request, "userSession");
if (userSession == null) {
String url = request.getServletPath();
String query = request.getQueryString();
ModelAndView modelAndView = new ModelAndView("SignonForm");
if (query != null) {
modelAndView.addObject("signonForwardAction", url+"?"+query);
}
else {
modelAndView.addObject("signonForwardAction", url);
}
throw new ModelAndViewDefiningException(modelAndView);
}
else {
return true;
}
}
protected Object formBackingObject(HttpServletRequest request) throws ModelAndViewDefiningException {
UserSession userSession = (UserSession) request.getSession().getAttribute("userSession");
Cart cart = (Cart) request.getSession().getAttribute("sessionCart");
if (cart != null) {
// Re-read account from DB at team's request.
Account account = this.petStore.getAccount(userSession.getAccount().getUsername());
OrderForm orderForm = new OrderForm();
orderForm.getOrder().initOrder(account, cart);
return orderForm;
}
else {
ModelAndView modelAndView = new ModelAndView("Error");
modelAndView.addObject("message", "An order could not be created because a cart could not be found.");
throw new ModelAndViewDefiningException(modelAndView);
}
}
private void throwAuthException(String message) throws ModelAndViewDefiningException {
logger.warn(message);
throw new ModelAndViewDefiningException(ControllerUtils.createJsonView(false, message));
}