当前位置: 首页>>代码示例>>Java>>正文


Java HttpServletResponse.setStatus方法代码示例

本文整理汇总了Java中javax.servlet.http.HttpServletResponse.setStatus方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.setStatus方法的具体用法?Java HttpServletResponse.setStatus怎么用?Java HttpServletResponse.setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.http.HttpServletResponse的用法示例。


在下文中一共展示了HttpServletResponse.setStatus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public Object run() {

    try {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletResponse response = ctx.getResponse();

        if (!rateLimiter.tryAcquire()) {
            HttpStatus httpStatus = HttpStatus.TOO_MANY_REQUESTS;

            response.setContentType(MediaType.TEXT_PLAIN_VALUE);
            response.setStatus(httpStatus.value());
            ctx.setResponseStatusCode(httpStatus.value());
            ctx.setSendZuulResponse(false);
        }
    } catch (Exception e) {
        ReflectionUtils.rethrowRuntimeException(e);
    }
    return null;
}
 
开发者ID:kenly333,项目名称:service-hive,代码行数:21,代码来源:RateLimitZuulFilter.java

示例2: logonStartAgain

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * The logon to start again
 *
 * @param context ServletContext
 * @param req HttpServletRequest
 * @param resp HttpServletResponse
 * @param ignoreFallback ignore fallback
 * @throws IOException
 */
private void logonStartAgain(ServletContext context, HttpServletRequest req, HttpServletResponse resp, boolean ignoreFallback) throws IOException
    {
    if (getLogger().isDebugEnabled())
        getLogger().debug("Issuing login challenge to browser.");
    // Force the logon to start again
    resp.setHeader("WWW-Authenticate", "Negotiate");
    
    if (!ignoreFallback && isFallbackEnabled())
    {
        includeFallbackAuth(context, req, resp);
    }
    
    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    writeLoginPageLink(context, req, resp);
    resp.flushBuffer();
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:26,代码来源:BaseKerberosAuthenticationFilter.java

示例3: restore

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping("Admin/RestorePedido")
public void restore(HttpSession session, Long id, HttpServletResponse response) {
	if(Permissoes.checar(session, EnumMetodo.RESTAURAR, entidade)){			//	Consulta a permissão
		dao.restore(id);													//	Ação no banco
		relatorio.gerarRelatorio(session, EnumMetodo.RESTAURAR, entidade);	//	Gera Relatório e armazena no banco
		response.setStatus(200);											//	Indica para a requisição AJAX que tudo ocorreu bem
	}
}
 
开发者ID:iurigodoy,项目名称:Monsters_Portal,代码行数:9,代码来源:PedidoController.java

示例4: batchAuth

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(value = "/auth/batch", method = RequestMethod.POST)
public String batchAuth(HttpServletResponse response, HttpServletRequest request) {
    String modifyUserId = JwtService.getConnUser(request).getUserId();
    String json = request.getParameter("JSON");
    List<UserRoleEntity> list = new ParseJson<UserRoleEntity>().toList(json);
    try {
        int size = roleService.batchAuth(list, modifyUserId);
        if (1 == size) {
            return Hret.success(200, "success", null);
        }
        response.setStatus(422);
        return Hret.error(422, "授权失败,用户已经拥有了这个角色", null);
    } catch (Exception e) {
        logger.info(e.getMessage());
        response.setStatus(421);
        return Hret.error(421, "授权失败,用户已经拥有了这个角色", null);
    }
}
 
开发者ID:hzwy23,项目名称:hauth-java,代码行数:19,代码来源:RoleController.java

示例5: search

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String query = req.getParameter("query");
    final PrintWriter writer = resp.getWriter();

    if (query == null || query.isEmpty()) {
        resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        writer.println("Usage:\n" +
            "GET /search?query=<search_query>\n" +
            "POST /search (body: search=<url_encoded_search_query>)");
        return;
    }

    metricSearch.search(query, writer);
}
 
开发者ID:yandex,项目名称:graphouse,代码行数:15,代码来源:MetricSearchServlet.java

示例6: preHandle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
		throws Exception {
	response.setHeader("Access-Control-Allow-Origin", "*");
	response.setHeader("Access-Control-Allow-Methods", "POST,GET,PUT,OPTIONS,DELETE");
	response.setHeader("Access-Control-Allow-Headers",
			"x-requested-with,Access-Control-Allow-Origin,EX-SysAuthToken,EX-JSESSIONID");

	String url = request.getServletPath();
	if (url.endsWith("/unauthorized") || url.endsWith("/forbidden")) {
		return super.preHandle(request, response, handler);
	}
	HttpSession session = request.getSession();
	String preRequest = (String) session.getAttribute(Constants.PREREQUEST);
	Long preRequestTime = (Long) session.getAttribute(Constants.PREREQUEST_TIME);
	if (preRequestTime != null && preRequest != null) { // 过滤频繁操作
		if ((url.equals(preRequest) || allRequest)
				&& System.currentTimeMillis() - preRequestTime < minRequestIntervalTime) {
			Integer maliciousRequestTimes = (Integer) session.getAttribute(Constants.MALICIOUS_REQUEST_TIMES);
			if (maliciousRequestTimes == null) {
				maliciousRequestTimes = 1;
			} else {
				maliciousRequestTimes++;
			}
			session.setAttribute(Constants.MALICIOUS_REQUEST_TIMES, maliciousRequestTimes);
			if (maliciousRequestTimes > maxMaliciousTimes) {
				response.setStatus(HttpCode.MULTI_STATUS.value());
				logger.warn("To intercept a malicious request : {}", url);
				return false;
			}
		} else {
			session.setAttribute(Constants.MALICIOUS_REQUEST_TIMES, 0);
		}
	}
	session.setAttribute(Constants.PREREQUEST, url);
	session.setAttribute(Constants.PREREQUEST_TIME, System.currentTimeMillis());
	return super.preHandle(request, response, handler);
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:38,代码来源:MaliciousRequestInterceptor.java

示例7: error404

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(value = "*")
public ModelAndView error404(HttpServletResponse response) {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("error/404");
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    return mv;
}
 
开发者ID:NeilRen,项目名称:NEILREN4J,代码行数:8,代码来源:ErrorController.java

示例8: update

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(method = RequestMethod.PUT)
public String update(HttpServletResponse response, HttpServletRequest request) {
    OrgEntity orgEntity = parse(request);
    RetMsg retMsg = orgService.update(orgEntity);
    if (retMsg.checkCode()) {
        return Hret.success(retMsg);
    }
    response.setStatus(retMsg.getCode());
    return Hret.error(retMsg);
}
 
开发者ID:hzwy23,项目名称:hauth-java,代码行数:11,代码来源:OrgController.java

示例9: render

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * Render model and view. Sets the response status to OK.
 *
 * @param response the response
 */
public static void render(final HttpServletResponse response) {
    try {
        final Map<String, Object> map = new HashMap<>();
        response.setStatus(HttpServletResponse.SC_OK);
        render(map, response);
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:16,代码来源:JsonViewUtils.java

示例10: handle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException
{
    // Allow Jetty RequestRetry exception to propogate to container
    Continuation.rethrowIfContinuation(cause);

    log.warn("Error: " + cause);
    if (cause instanceof SecurityException && log.isDebugEnabled())
    {
        log.debug("- User Agent: " + request.getHeader(HttpConstants.HEADER_USER_AGENT));
        log.debug("- Remote IP:  " + request.getRemoteAddr());
        log.debug("- Request URL:" + request.getRequestURL());
        log.debug("- Query:      " + request.getQueryString());
        log.debug("- Method:     " + request.getMethod());
    }

    // We are going to act on this in engine.js so we are hoping that
    // that SC_NOT_IMPLEMENTED (501) is not something that the servers
    // use that much. I would have used something unassigned like 506+
    // But that could cause future problems and might not get through
    // proxies and the like
    response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
    response.setContentType(MimeConstants.MIME_HTML);
    PrintWriter out = response.getWriter();
    out.println(cause.getMessage());

    log.warn("Sent 501", cause);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:28,代码来源:ExceptionHandler.java

示例11: ping

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private void ping(HttpServletResponse resp) throws IOException {
    if (allowColdRun || metricSearch.isMetricTreeLoaded()) {
        resp.setStatus(HttpServletResponse.SC_OK);
        resp.getWriter().print("0;OK");
        return;
    }

    resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    resp.getWriter().println("2;Metric tree not loaded ");
}
 
开发者ID:yandex,项目名称:graphouse,代码行数:11,代码来源:MonitoringServlet.java

示例12: replyAjax

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@PostMapping({"/{id}", "/{id}/{title}"})
public String replyAjax(@PathVariable String id, @PathVariable(required = false) String title,
		HttpServletRequest req, HttpServletResponse res, Model model) throws IOException {
	Post showPost = pc.read(id);
	Profile authUser = utils.getAuthUser(req);
	if (showPost != null && !showPost.isClosed() && !showPost.isReply()) {
		//create new answer
		Reply answer = utils.populate(req, new Reply(), "body");
		Map<String, String> error = utils.validate(answer);
		if (!error.containsKey("body")) {
			answer.setTitle(showPost.getTitle());
			answer.setCreatorid(authUser.getId());
			answer.setParentid(showPost.getId());
			answer.create();

			showPost.setAnswercount(showPost.getAnswercount() + 1);
			if (showPost.getAnswercount() >= MAX_REPLIES_PER_POST) {
				showPost.setCloserid("0");
			}
			// update without adding revisions
			pc.update(showPost);
			utils.addBadgeAndUpdate(authUser, Profile.Badge.EUREKA, answer.getCreatorid().equals(showPost.getCreatorid()));
			answer.setAuthor(authUser);
			model.addAttribute("showPost", showPost);
			model.addAttribute("answerslist", Collections.singletonList(answer));
			return "reply";
		}
	}
	if (utils.isAjaxRequest(req)) {
		res.setStatus(200);
		return "base";
	} else {
		return "redirect:" + FEEDBACKLINK + "/" + id;
	}
}
 
开发者ID:Erudika,项目名称:scoold,代码行数:36,代码来源:FeedbackController.java

示例13: delete

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public String delete(HttpServletResponse response, HttpServletRequest request) {
    String json = request.getParameter("JSON");
    List<UserEntity> list = new GsonBuilder().create().fromJson(json,
            new TypeToken<List<UserEntity>>() {
            }.getType());
    int size = userService.delete(list);
    if (size == 1) {
        return Hret.success(200, "success", null);
    }
    response.setStatus(421);
    return Hret.error(421, "删除用户信息失败, 请联系管理员", null);
}
 
开发者ID:hzwy23,项目名称:batch-scheduler,代码行数:14,代码来源:UserController.java

示例14: handleRequestValidationException

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@ExceptionHandler({RequestValidationException.class})
@ResponseBody
public ExceptionResponse handleRequestValidationException(GenericException ex, HttpServletRequest request,
                                                          HttpServletResponse httpResponse) {
    log.error("Request validation exception occurred :", ex);
    ExceptionResponse exception = new ExceptionResponse();
    exception.setCode(ex.getErrCode());
    exception.setMessage(ex.getErrMessage());
    httpResponse.setStatus(400);
    return exception;
}
 
开发者ID:dixantmittal,项目名称:scalable-task-scheduler,代码行数:12,代码来源:ControllerExceptionHandler.java

示例15: resolveException

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
                                     Object o, Exception e) {
    //自定义异常拦截
    if (e instanceof RuntimeException) {
        response.setStatus(IConstants.RBAC_AJAX_EXCEPTION);
    }
    //判断是否是ajax
    if (CommonUtils.isAsyncRequest(request)) {
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.write(e.getMessage());
            writer.flush();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        } finally {
            if (writer != null) {
                writer.close();
            }
        }
        return null;
    } else {
        HashMap<String, Object> hashMap = new HashMap<>();
        hashMap.put("message", e.getMessage());
        return new ModelAndView("public/errorPage", hashMap);
    }
}
 
开发者ID:cx118118,项目名称:ssm-rbac,代码行数:29,代码来源:GlobalExceptionHandler.java


注:本文中的javax.servlet.http.HttpServletResponse.setStatus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。