當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse類代碼示例

本文整理匯總了Java中javax.servlet.http.HttpServletResponse的典型用法代碼示例。如果您正苦於以下問題:Java HttpServletResponse類的具體用法?Java HttpServletResponse怎麽用?Java HttpServletResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpServletResponse類屬於javax.servlet.http包,在下文中一共展示了HttpServletResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doGet

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
protected void doGet( HttpServletRequest req, HttpServletResponse resp )
		throws ServletException, IOException {		
	Token token=new Token();
	
	// Is ralasafe security enabled?
	boolean secured=RalasafeController.isSecured();
	
	if( secured ) {
		User currentUser=WebRalasafe.getCurrentUser( req );
		token.setCanAssignRoleToUser( Ralasafe.hasPrivilege( Privilege.ASSIGN_ROLE_TO_USER_ID, currentUser ) );
		token.setCanAdminRole( Ralasafe.hasPrivilege( Privilege.ROLE_ADMIN_ID, currentUser ) );
		token.setCanAdminPolicy( Ralasafe.hasPrivilege( Privilege.POLICY_ADMIN_ID, currentUser ) );
	}
	
	req.setAttribute( "token", token );
	WebUtil.forward( req, resp, "/ralasafe/main.jsp" );
}
 
開發者ID:yswang0927,項目名稱:ralasafe,代碼行數:18,代碼來源:DesignerAction.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: getDelete

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
@GetMapping("/delete/{id}")
public String getDelete(HttpServletRequest request, HttpServletResponse response, @PathVariable long id,
						Model model) throws IOException {
	HttpSession session = request.getSession(true);
	Entry entry = getEntryDao().getEntry(id);

	if(entry == null) {
		response.sendError(HttpServletResponse.SC_NOT_FOUND);
		return null;
	}

	if(canEdit(session, entry)) {
		model.addAttribute("entry", entry);
		return "delete";
	}

	response.sendError(HttpServletResponse.SC_FORBIDDEN);
	return null;
}
 
開發者ID:kalsowerus,項目名稱:Guestbook9001,代碼行數:20,代碼來源:EditController.java

示例4: getActionResult

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
@Override
@RequestMapping(value = ApiConfig.ACTION_RESULTS_BASE + "/{actionResultId}", method = RequestMethod.GET,
        headers = ApiConfig.API_HEADERS, produces = {ApiConfig.API_PRODUCES})
@ResponseBody
public ActionResult getActionResult(@PathVariable final String actionResultId,
        @CookieValue(value = SessionManager.SESSION_COOKIE, required = false) final String sessionId,
        final HttpServletResponse response) throws InvalidActionSpecificationException, NoSuchProviderException,
        NoSuchSessionException, NoSuchItemTypeException {
    if (rateLimiter.tryAcquire()) {
        if (actionResultId == null) {
            throw new BadRequestException("actionResultId cannot be null");
        }
        UUID uuid = UUID.fromString(actionResultId);
        Session session = modelValidator.validateSession(sessionId, response);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Lookup action result " + actionResultId + " for session " + sessionId);
        }
        synchronized (session) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Assigned session " + session.getId());
            }
            ActionResult actionResult = actionManager.getActionResult(session, uuid);
            return actionResult;
        }
    } else {
        throw new ApiThrottlingException("Exceeded max number of requests per second");
    }
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:29,代碼來源:LoomServiceImpl.java

示例5: RewriteIvcResponseWrapper

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
public RewriteIvcResponseWrapper(HttpServletResponse response, String tag) {
    super(response);
    this.tag = tag;
    this.response = response;
    try {
        this.outputStream = response.getOutputStream();
        // 由於tomcat等實現類會記錄是否調用了getOutputStream方法,故此處進行這種操作
        response.reset();
    }
    catch (IOException e) {
        // 出現異常時則將異常信息放入
        builder.append(e.toString());
    }
    this.rewriteOutStream = new RewriteIvcOutputStream(outputStream, response.getCharacterEncoding());
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:16,代碼來源:RewriteIvcResponseWrapper.java

示例6: modifyPassword

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
 * 修改密碼
 *
 * @param user
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/modifyPassword")
public String modifyPassword(User user, HttpServletResponse response) throws Exception {
    String MD5pwd = MD5Util.MD5Encode(user.getPassword(), "UTF-8");
    user.setPassword(MD5pwd);
    int resultTotal = userService.updateUser(user);
    JSONObject result = new JSONObject();
    if (resultTotal > 0) {
        result.put("success", true);
    } else {
        result.put("success", false);
    }
    log.info("request: user/modifyPassword , user: " + user.toString());
    ResponseUtil.write(response, result);
    return null;
}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:24,代碼來源:UserController.java

示例7: testCheckPreFlightRequestTypeOriginNotAllowed

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
@Test
public void testCheckPreFlightRequestTypeOriginNotAllowed()
        throws ServletException, IOException {
    TesterHttpServletRequest request = new TesterHttpServletRequest();
    TesterHttpServletResponse response = new TesterHttpServletResponse();
    request.setHeader(CorsFilter.REQUEST_HEADER_ORIGIN,
            "www.ebay.com");
    request.setHeader(
            CorsFilter.REQUEST_HEADER_ACCESS_CONTROL_REQUEST_METHOD,
            "PUT");
    request.setMethod("OPTIONS");
    CorsFilter corsFilter = new CorsFilter();
    corsFilter.init(TesterFilterConfigs
            .getSecureFilterConfig());
    corsFilter.doFilter(request, response, filterChain);
    Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN,
            response.getStatus());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:19,代碼來源:TestCorsFilter.java

示例8: getMixQuotedParameters

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
 * Get header parameter values
 *
 * @throws Exception
 */
@Test
public void getMixQuotedParameters() throws Exception {
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      response.setStatus(HTTP_OK);
      response.setHeader("a", "value; b=c; d=\"e\"");
    }
  };
  HttpRequest request = get(url);
  assertTrue(request.ok());
  Map<String, String> params = request.parameters("a");
  assertNotNull(params);
  assertEquals(2, params.size());
  assertEquals("c", params.get("b"));
  assertEquals("e", params.get("d"));
}
 
開發者ID:junicorn,項目名稱:NiuBi,代碼行數:24,代碼來源:HttpRequestTest.java

示例9: resolveException

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
 * Resolve exception.
 *
 * @param request the request
 * @param response the response
 * @param ex the exception
 * @return the model and view
 * @throws IOException the iO exception
 */
@ExceptionHandler
public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response,
                                     final Exception ex) throws IOException {

    logger.error(ex.getMessage(), ex);
    final String contentType = request.getHeader(AJAX_REQUEST_HEADER_NAME);
    if (contentType != null && contentType.equals(AJAX_REQUEST_HEADER_VALUE)) {
        logger.debug("Handling exception {} for ajax request indicated by header {}",
                ex.getClass().getName(), AJAX_REQUEST_HEADER_NAME);
        JsonViewUtils.renderException(ex, response);
        return null;
    } else {
        logger.trace("Unable to resolve exception {} for request. Ajax request header {} not found.",
                ex.getClass().getName(), AJAX_REQUEST_HEADER_NAME);
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        final ModelAndView mv = new ModelAndView("errors");
        mv.addObject(ex);
        return mv;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:31,代碼來源:AbstractManagementController.java

示例10: handleRequestInternal

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    // create our model object
    Map<String,Object> model = new HashMap<String,Object>();

    // NOTE: we cannot get the current location from here -AZ
    //String locationId = external.getCurrentLocationId();
    String userId = external.getCurrentUserId();
    model.put("currentUserId", userId);
    model.put("isSuperUser", external.isUserAdmin(userId));

    /* Cannot show the special uploader here because we cannot get the current location
    String widgetPlayerUploadSpecialId = "";
    String widgetPlayerUploadSpecialKS = "";
    if (service.isKalturaUploadSpecial(userId, locationId)) {
        widgetPlayerUploadSpecialId = service.getKalturaWidgetId(Widget.UPLOADER_SPECIAL);
        widgetPlayerUploadSpecialKS = service.getKalturaClient(MediaService.KS_PERM_LIST).getSessionId();
    }
    model.put("uploadSpecialId", widgetPlayerUploadSpecialId);
    model.put("uploadSpecialKS", widgetPlayerUploadSpecialKS);
     */

    return new ModelAndView("fckEditorSelector", model);
}
 
開發者ID:ITYug,項目名稱:kaltura-ce-sakai-extension,代碼行數:27,代碼來源:FckKalturaSelectorController.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: getWithEscapedMappedQueryParams

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
 * Verify GET with escaped query parameters
 *
 * @throws Exception
 */
@Test
public void getWithEscapedMappedQueryParams() throws Exception {
  Map<String, String> inputParams = new HashMap<String, String>();
  inputParams.put("name", "us er");
  inputParams.put("number", "100");
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("name", request.getParameter("name"));
      outputParams.put("number", request.getParameter("number"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = get(url, inputParams, true);
  assertTrue(request.ok());
  assertEquals("GET", method.get());
  assertEquals("us er", outputParams.get("name"));
  assertEquals("100", outputParams.get("number"));
}
 
開發者ID:junicorn,項目名稱:NiuBi,代碼行數:29,代碼來源:HttpRequestTest.java

示例13: logAndReturnException

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
    * Clean return of Exception in JSon format & log Exception.
    * @param request 
    * @param response
    * @param out
    * @param exception
    */
   public static void logAndReturnException(HttpServletRequest request,
    HttpServletResponse response, PrintWriter out, Exception exception) {

try {
    JsonErrorReturn jsonErrorReturn = new JsonErrorReturn(response,
    	HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
    	JsonErrorReturn.ERROR_ACEQL_ERROR, exception.getMessage(),
    	ExceptionUtils.getStackTrace(exception));

    out.println(jsonErrorReturn.build());
    LoggerUtil.log(request, exception);
} catch (Exception e) {
    // Should never happen
    e.printStackTrace();
}

   }
 
開發者ID:kawansoft,項目名稱:aceql-http,代碼行數:25,代碼來源:ExceptionReturner.java

示例14: exportFile

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
 * 向客戶端下載文件,彈出下載框.
 *
 * @param response(HttpServletResponse)
 * @param file(需要下載的文件)
 * @param isDel(下載完成後是否刪除該文件)
 * @throws IOException
 */
public static void exportFile(HttpServletResponse response, File file, boolean isDel) throws IOException {
    OutputStream out = null;
    InputStream in = null;

    // 獲得文件名
    String filename = URLEncoder.encode(file.getName(), "UTF-8");
    response.reset();
    // 定義輸出類型(下載)
    response.setContentType("application/x-msdownload");
    response.setHeader("Location", filename);
    // 定義輸出文件頭
    response.setHeader("Content-Disposition", "attachment;filename=" + filename);
    out = response.getOutputStream();
    in = new FileInputStream(file.getPath());

    byte[] buffer = new byte[1024];
    int i = -1;
    while ((i = in.read(buffer)) != -1) {
        out.write(buffer, 0, i);
    }

    in.close();
    out.close();

    if (isDel) {
        //刪除文件,刪除前關閉所有的Stream.
        file.delete();
    }

}
 
開發者ID:tong12580,項目名稱:OutsourcedProject,代碼行數:39,代碼來源:Excel.java

示例15: save

import javax.servlet.http.HttpServletResponse; //導入依賴的package包/類
/**
 * 添加或修改管理員
 *
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/save")
public String save(User user, HttpServletResponse response) throws Exception {
    int resultTotal = 0;
    String MD5pwd = MD5Util.MD5Encode(user.getPassword(), "UTF-8");
    user.setPassword(MD5pwd);
    if (user.getId() == null) {
        resultTotal = userService.addUser(user);
    } else {
        resultTotal = userService.updateUser(user);
    }
    JSONObject result = new JSONObject();
    if (resultTotal > 0) {
        result.put("success", true);
    } else {
        result.put("success", false);
    }
    log.info("request: user/save , user: " + user.toString());
    ResponseUtil.write(response, result);
    return null;
}
 
開發者ID:ZHENFENG13,項目名稱:ssm-demo,代碼行數:28,代碼來源:UserController.java


注:本文中的javax.servlet.http.HttpServletResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。