本文整理匯總了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;
}
示例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");
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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;
}
示例12: handleConversionException
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
@ExceptionHandler
void handleConversionException(ConversionException e, HttpServletResponse response) throws IOException {
response.sendError(e.getStatusCode(), e.getMessage());
}
示例13: doGet
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendError(403);
}
示例14: doGet
import javax.servlet.http.HttpServletResponse; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.sendError(403);
}
示例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;
}