本文整理匯總了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;
}
示例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();
}
示例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
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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 ");
}
示例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;
}
}
示例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);
}
示例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;
}
示例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);
}
}