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


Java HttpServletResponse.sendError方法代码示例

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


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

示例1: preHandle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public final boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object o) throws Exception {
    // we only care about post because that's the only instance where we can get anything useful besides IP address.
    if (!"POST".equals(request.getMethod())) {
        return true;
    }

    if (exceedsThreshold(request)) {
        recordThrottle(request);
        request.setAttribute(WebUtils.CAS_ACCESS_DENIED_REASON, "screen.blocked.message");
        response.sendError(HttpStatus.SC_FORBIDDEN,
                "Access Denied for user [" + request.getParameter(usernameParameter)
                + "] from IP Address [" + request.getRemoteAddr() + ']');
        return false;
    }

    return true;
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:19,代码来源:AbstractThrottledSubmissionHandlerInterceptorAdapter.java

示例2: preHandle

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public boolean preHandle(HttpServletRequest request, 
		HttpServletResponse response, Object handler)
				throws Exception {
	String uri = request.getRequestURI();
	Weaver weaver = weaverService.getCurrentWeaver();
	if(uri.contains("/tags:")){
		String tags = uri.substring(uri.indexOf("/tags:")+6);
		if(tags.contains("/"))
			tags = tags.substring(0, tags.indexOf("/"));
		tags = URLDecoder.decode(tags, "UTF-8");
		List<String> tagList = tagService.stringToTagList(tags);
		if(!tagService.validateTag(tagList, weaver)){
			response.sendError(400);				
			return false;
		}

	}
	return true;
}
 
开发者ID:forweaver,项目名称:forweaver2.0,代码行数:20,代码来源:CommunityIntercepter.java

示例3: commence

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void commence(HttpServletRequest request,
                     HttpServletResponse response,
                     AuthenticationException authException) throws IOException {
    // This is invoked when user tries to access a secured REST resource without supplying any credentials
    // We should just send a 401 Unauthorized response because there is no 'login page' to redirect to
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}
 
开发者ID:zzqfsy,项目名称:spring-jwt-starter,代码行数:9,代码来源:JwtAuthenticationEntryPoint.java

示例4: service

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * Execute a request.  The path-info of the request selects the bean.
 * Once the bean's selected, it will be applied.
 */
@Override
public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException
{
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse res = (HttpServletResponse) response;

    if ("POST".equals(req.getMethod()))
    {
        this.processPost(request, response);
    }
    else if ("GET".equals(req.getMethod()))
    {
        this.printStatistics(res);
    }
    else
    {
        String errorMessage = "JRPIP Servlet Requires POST";
        res.sendError(405, errorMessage);
    }
}
 
开发者ID:goldmansachs,项目名称:jrpip,代码行数:25,代码来源:JrpipServlet.java

示例5: render

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void render(final HttpServletRequest request, final HttpServletResponse response) {
	response.setContentType("text/html");
	response.setCharacterEncoding("UTF-8");

	try {
		final Template template = ConsoleRenderer.TEMPLATE_CFG.getTemplate("kill-browser.ftl");

		final PrintWriter writer = response.getWriter();

		final StringWriter stringWriter = new StringWriter();

		template.setOutputEncoding("UTF-8");
		template.process(getDataModel(), stringWriter);

		final String pageContent = stringWriter.toString();

		writer.write(pageContent);
		writer.flush();
		writer.close();
	} catch (final Exception e) {
		try {
			response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		} catch (final IOException ex) {
			logger.error("Can not sned error 500!", ex);
		}
	}
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:29,代码来源:IndexProcessor.java

示例6: getLearningDesignThumbnail

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public ActionForward getLearningDesignThumbnail(ActionMapping mapping, ActionForm form, HttpServletRequest req,
    HttpServletResponse res) throws IOException {
Long learningDesignId = WebUtil.readLongParam(req, CentralConstants.PARAM_LEARNING_DESIGN_ID);
String imagePath = LearningDesignService.getLearningDesignSVGPath(learningDesignId);
File imageFile = new File(imagePath);
if (!imageFile.canRead()) {
    res.sendError(HttpServletResponse.SC_NOT_FOUND);
    return null;
}

boolean download = WebUtil.readBooleanParam(req, "download", false);
// should the image be downloaded or a part of page?
if (download) {
    String name = getLearningDesignService()
	    .getLearningDesignDTO(learningDesignId, getUser().getLocaleLanguage()).getTitle();
    name += "." + "svg";
    name = FileUtil.encodeFilenameForDownload(req, name);
    res.setContentType("application/x-download");
    res.setHeader("Content-Disposition", "attachment;filename=" + name);
} else {
    res.setContentType("image/svg+xml");
}

FileInputStream input = new FileInputStream(imagePath);
OutputStream output = res.getOutputStream();
IOUtils.copy(input, output);
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);

return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:32,代码来源:HomeAction.java

示例7: apply

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public boolean apply(HttpServletRequest request, HttpServletResponse response) throws IOException {
	if (isValidStateChangingRequest(extractNonceFromRequest(request),
			extractNonceFromSession(request.getSession(false), Constants.CSRF_REST_NONCE_SESSION_ATTR_NAME))) {
		return true;
	}

	storeNonceToResponse(response, Constants.CSRF_REST_NONCE_HEADER_NAME,
			Constants.CSRF_REST_NONCE_HEADER_REQUIRED_VALUE);
	response.sendError(getDenyStatus(), sm.getString("restCsrfPreventionFilter.invalidNonce"));
	return false;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:13,代码来源:RestCsrfPreventionFilter.java

示例8: writeError

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public static void writeError(HttpServletResponse response, Status error) {
	//response.setStatus(error.toInt());
	try {
		response.sendError(error.toInt());
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:auslides,项目名称:stateless-shiro,代码行数:9,代码来源:HTTP.java

示例9: doGet

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/** Handle fsck request */
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response
    ) throws IOException {
  @SuppressWarnings("unchecked")
  final Map<String,String[]> pmap = request.getParameterMap();
  final PrintWriter out = response.getWriter();
  final InetAddress remoteAddress = 
    InetAddress.getByName(request.getRemoteAddr());
  final ServletContext context = getServletContext();    
  final Configuration conf = NameNodeHttpServer.getConfFromContext(context);

  final UserGroupInformation ugi = getUGI(request, conf);
  try {
    ugi.doAs(new PrivilegedExceptionAction<Object>() {
      @Override
      public Object run() throws Exception {
        NameNode nn = NameNodeHttpServer.getNameNodeFromContext(context);
        
        final FSNamesystem namesystem = nn.getNamesystem();
        final BlockManager bm = namesystem.getBlockManager();
        final int totalDatanodes = 
            namesystem.getNumberOfDatanodes(DatanodeReportType.LIVE); 
        new NamenodeFsck(conf, nn,
            bm.getDatanodeManager().getNetworkTopology(), pmap, out,
            totalDatanodes, remoteAddress).fsck();
        
        return null;
      }
    });
  } catch (InterruptedException e) {
    response.sendError(400, e.getMessage());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:35,代码来源:FsckServlet.java

示例10: commence

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
		throws IOException, ServletException {

	response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
 
开发者ID:luotuo,项目名称:springboot-security-wechat,代码行数:7,代码来源:RESTAuthenticationEntryPoint.java

示例11: getUsers

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
    * Refreshes user list.
    */
   public ActionForward getUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws IOException, ServletException, JSONException {
Map<String, Object> map = new HashMap<String, Object>();
copySearchParametersFromRequestToMap(request, map);
Long lessonId = (Long) map.get(AttributeNames.PARAM_LESSON_ID);
Integer orgId = (Integer) map.get(AttributeNames.PARAM_ORGANISATION_ID);

if (lessonId != null) {
    if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(),
	    "get users for lesson email notifications", false)) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson");
	return null;
    }
} else if (orgId != null) {
    if (!getSecurityService().isGroupMonitor(orgId, getCurrentUser().getUserID(),
	    "get users for course email notifications", false)) {
	response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the organisation");
	return null;
    }
}

IMonitoringService monitoringService = MonitoringServiceProxy
	.getMonitoringService(getServlet().getServletContext());

int searchType = (Integer) map.get("searchType");
Long activityId = (Long) map.get(AttributeNames.PARAM_ACTIVITY_ID);
Integer xDaystoFinish = (Integer) map.get("daysToDeadline");
String[] lessonIds = (String[]) map.get("lessonIDs");
Collection<User> users = monitoringService.getUsersByEmailNotificationSearchType(searchType, lessonId,
	lessonIds, activityId, xDaystoFinish, orgId);

JSONArray cellarray = new JSONArray();

JSONObject responcedata = new JSONObject();
responcedata.put("total", "" + users.size());
responcedata.put("page", "" + 1);
responcedata.put("records", "" + users.size());

for (User user : users) {
    JSONArray cell = new JSONArray();
    cell.put(StringEscapeUtils.escapeHtml(user.getFirstName()) + " "
	    + StringEscapeUtils.escapeHtml(user.getLastName()) + " ["
	    + StringEscapeUtils.escapeHtml(user.getLogin()) + "]");

    JSONObject cellobj = new JSONObject();
    cellobj.put("id", "" + user.getUserId());
    cellobj.put("cell", cell);
    cellarray.put(cellobj);
}
responcedata.put("rows", cellarray);
response.setContentType("application/json;charset=utf-8");
response.getWriter().print(new String(responcedata.toString()));
return null;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:58,代码来源:EmailNotificationsAction.java

示例12: handleConversionException

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@ExceptionHandler
void handleConversionException(ConversionException e, HttpServletResponse response) throws IOException {
	response.sendError(e.getStatusCode(), e.getMessage());
}
 
开发者ID:marrow16,项目名称:ColorConverter,代码行数:5,代码来源:ProfilesEndpoint.java

示例13: doGet

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
  response.sendError(403);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:4,代码来源:SubmitTask.java

示例14: doGet

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.sendError(403);
}
 
开发者ID:Luodian,项目名称:Higher-Cloud-Computing-Project,代码行数:4,代码来源:Active.java

示例15: checkIfNoneMatch

import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
 * Check if the if-none-match condition is satisfied.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param resourceAttributes File object
 * @return boolean true if the resource meets the specified condition,
 * and false if the condition is not satisfied, in which case request
 * processing is stopped
 */
protected boolean checkIfNoneMatch(HttpServletRequest request,
                                 HttpServletResponse response,
                                 ResourceAttributes resourceAttributes)
    throws IOException {

    String eTag = resourceAttributes.getETag();
    String headerValue = request.getHeader("If-None-Match");
    if (headerValue != null) {

        boolean conditionSatisfied = false;

        if (!headerValue.equals("*")) {

            StringTokenizer commaTokenizer =
                new StringTokenizer(headerValue, ",");

            while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) {
                String currentToken = commaTokenizer.nextToken();
                if (currentToken.trim().equals(eTag))
                    conditionSatisfied = true;
            }

        } else {
            conditionSatisfied = true;
        }

        if (conditionSatisfied) {

            // For GET and HEAD, we should respond with
            // 304 Not Modified.
            // For every other method, 412 Precondition Failed is sent
            // back.
            if ( ("GET".equals(request.getMethod()))
                 || ("HEAD".equals(request.getMethod())) ) {
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                response.setHeader("ETag", eTag);

                return false;
            }
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return false;
        }
    }
    return true;

}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:57,代码来源:DefaultServlet.java


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