Java Code Examples for com.ruoyi.common.utils.ServletUtils#renderString()
The following examples show how to use
com.ruoyi.common.utils.ServletUtils#renderString() .
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: RepeatSubmitInterceptor.java From supplierShop with MIT License | 6 votes |
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; Method method = handlerMethod.getMethod(); RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); if (annotation != null) { if (this.isRepeatSubmit(request)) { AjaxResult ajaxResult = AjaxResult.error("不允许重复提交,请稍后再试"); ServletUtils.renderString(response, JSON.marshal(ajaxResult)); return false; } } return true; } else { return super.preHandle(request, response, handler); } }
Example 2
Source File: LogoutSuccessHandlerImpl.java From RuoYi-Vue with MIT License | 6 votes |
/** * 退出处理 * * @return */ @Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { LoginUser loginUser = tokenService.getLoginUser(request); if (StringUtils.isNotNull(loginUser)) { String userName = loginUser.getUsername(); // 删除用户缓存记录 tokenService.delLoginUser(loginUser.getToken()); // 记录用户退出日志 AsyncManager.me().execute(AsyncFactory.recordLogininfor(userName, Constants.LOGOUT, "退出成功")); } ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(HttpStatus.SUCCESS, "退出成功"))); }
Example 3
Source File: RepeatSubmitInterceptor.java From RuoYi-Vue with MIT License | 6 votes |
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; Method method = handlerMethod.getMethod(); RepeatSubmit annotation = method.getAnnotation(RepeatSubmit.class); if (annotation != null) { if (this.isRepeatSubmit(request)) { AjaxResult ajaxResult = AjaxResult.error("不允许重复提交,请稍后再试"); ServletUtils.renderString(response, JSONObject.toJSONString(ajaxResult)); return false; } } return true; } else { return super.preHandle(request, response, handler); } }
Example 4
Source File: KickoutSessionFilter.java From supplierShop with MIT License | 5 votes |
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 5
Source File: SysLoginController.java From supplierShop with MIT License | 5 votes |
@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 6
Source File: AuthenticationEntryPointImpl.java From RuoYi-Vue with MIT License | 5 votes |
@Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException { int code = HttpStatus.UNAUTHORIZED; String msg = StringUtils.format("请求访问:{},认证失败,无法访问系统资源", request.getRequestURI()); ServletUtils.renderString(response, JSON.toJSONString(AjaxResult.error(code, msg))); }
Example 7
Source File: KickoutSessionFilter.java From RuoYi with Apache License 2.0 | 5 votes |
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 |
@GetMapping("/login") public String login(HttpServletRequest request, HttpServletResponse response) { // 如果是Ajax请求,返回Json字符串。 if (ServletUtils.isAjaxRequest(request)) { return ServletUtils.renderString(response, "{\"code\":\"1\",\"msg\":\"未登录或登录超时。请重新登录\"}"); } return "login"; }