當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。