当前位置: 首页>>代码示例>>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;未经允许,请勿转载。