Java Code Examples for com.ruoyi.common.utils.ServletUtils#isAjaxRequest()

The following examples show how to use com.ruoyi.common.utils.ServletUtils#isAjaxRequest() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalExceptionHandler.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 权限校验失败 如果请求为ajax返回json,普通请求跳转页面
 */
@ExceptionHandler(AuthorizationException.class)
public Object handleAuthorizationException(HttpServletRequest request, AuthorizationException e)
{
    log.error(e.getMessage(), e);
    if (ServletUtils.isAjaxRequest(request))
    {
        return AjaxResult.error(PermissionUtils.getMsg(e.getMessage()));
    }
    else
    {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error/unauth");
        return modelAndView;
    }
}
 
Example 2
Source File: GlobalExceptionHandler.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 业务异常
 */
@ExceptionHandler(BusinessException.class)
public Object businessException(HttpServletRequest request, BusinessException e)
{
    log.error(e.getMessage(), e);
    if (ServletUtils.isAjaxRequest(request))
    {
        return AjaxResult.error(e.getMessage());
    }
    else
    {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("errorMessage", e.getMessage());
        modelAndView.setViewName("error/business");
        return modelAndView;
    }
}
 
Example 3
Source File: KickoutSessionFilter.java    From supplierShop with MIT License 5 votes vote down vote up
private boolean isAjaxResponse(ServletRequest request, ServletResponse response) throws IOException
{
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    if (ServletUtils.isAjaxRequest(req))
    {
        AjaxResult ajaxResult = AjaxResult.error("您已在别处登录,请您修改密码或重新登录");
        ServletUtils.renderString(res, objectMapper.writeValueAsString(ajaxResult));
    }
    else
    {
        WebUtils.issueRedirect(request, response, kickoutUrl);
    }
    return false;
}
 
Example 4
Source File: SysLoginController.java    From supplierShop with MIT License 5 votes vote down vote up
@GetMapping("/login")
public String login(HttpServletRequest request, HttpServletResponse response)
{
    // 如果是Ajax请求,返回Json字符串。
    if (ServletUtils.isAjaxRequest(request))
    {
        return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
    }

    return "login";
}
 
Example 5
Source File: GlobalExceptionHandler.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 权限校验失败 如果请求为ajax返回json,普通请求跳转页面
 */
@ExceptionHandler(AuthorizationException.class)
public Object handleAuthorizationException(HttpServletRequest request, AuthorizationException e) {
    log.error(e.getMessage(), e);
    if (ServletUtils.isAjaxRequest(request)) {
        return AjaxResult.error(PermissionUtils.getMsg(e.getMessage()));
    } else {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error/unauth");
        return modelAndView;
    }
}
 
Example 6
Source File: GlobalExceptionHandler.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
/**
 * 业务异常
 */
@ExceptionHandler(BusinessException.class)
public Object businessException(HttpServletRequest request, BusinessException e) {
    log.error(e.getMessage(), e);
    if (ServletUtils.isAjaxRequest(request)){
        return AjaxResult.error(e.getMessage());
    }else{
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("errorMessage", e.getMessage());
        modelAndView.setViewName("error/business");
        return modelAndView;
    }
}
 
Example 7
Source File: KickoutSessionFilter.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
private boolean isAjaxResponse(ServletRequest request, ServletResponse response) throws IOException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;
    if (ServletUtils.isAjaxRequest(req)) {
        AjaxResult ajaxResult = AjaxResult.error("您已在别处登录,请您修改密码或重新登录");
        ServletUtils.renderString(res, JSONUtil.toJsonStr(ajaxResult));
    } else {
        WebUtils.issueRedirect(request, response, kickoutUrl);
    }
    return false;
}
 
Example 8
Source File: SysLoginController.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
@GetMapping("/login")
public String login(HttpServletRequest request, HttpServletResponse response) {
    // 如果是Ajax请求,返回Json字符串。
    if (ServletUtils.isAjaxRequest(request)) {
        return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}");
    }

    return "login";
}