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


Java SlingHttpServletResponse.sendRedirect方法代码示例

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


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

示例1: doPost

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
		throws ServletException, IOException {
	try {
		final Map<String, InputStream> files = Maps.newHashMap();
		for (RequestParameter file : request.getRequestParameters("file")) {
			files.put(file.getFileName(), file.getInputStream());
		}

		final List<Script> scripts = scriptStorage
				.saveAll(files, isOverwrite(request), request.getResourceResolver());

		if (shouldRedirect(request)) {
			response.sendRedirect(getRedirectTo(request));
		} else {
			ServletUtils.writeJson(response, ScriptUtils.toJson(scripts));
		}
	} catch (RepositoryException e) {
		response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		ServletUtils.writeJson(response, "Cannot save script in repository: " + e.getMessage());
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:23,代码来源:ScriptUploadServlet.java

示例2: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
  Session session = request.getResourceResolver().adaptTo(Session.class);
  try {
    writeJcrContent(session);
    response.sendRedirect(request.getResource().getPath() + ".jcrreadsample.txt");
  }
  catch (RepositoryException ex) {
    throw new ServletException(ex);
  }
}
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:12,代码来源:JcrWriteSample.java

示例3: doPost

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

  updateLikeCounter(request);

  // return to main view
  response.sendRedirect(request.getResource().getPath() + ".html");
}
 
开发者ID:adaptto,项目名称:2015-sling-rookie-session,代码行数:9,代码来源:LikeMe.java

示例4: doFilter

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
        ServletException {

    // Since this is a Sling Filter, the request and response objects are guaranteed to be of types
    // SlingHttpServletRequest and SlingHttpServletResponse.

    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) response;
    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) request;
    final Resource resource = slingRequest.getResource();

    if (resource.getPath().startsWith("/redirect-me")) {

        // Is the SlingFilterScope is REQUEST, redirects can be issued.
        slingResponse.sendRedirect("/some/redirect.html");

        // Stop processing the request chain
        return;
    }

    // Content can be written tot he response before and after the chain execution
    
    // Forcing false in this sample so else this will break AEM when installed
    if (false && response.getContentType().contains("html")) {
        // In this example, checking for html response type since the comments are HTML format and would break
        // binary, json, etc. responses

        // Write some more content to the response before this chain has executed
        //response.getWriter().write("<!-- Written from the Sample Sling Filter BEFORE the next include -->");

        // Proceed with the rest of the Filter chain
        chain.doFilter(request, response);

        // Write some more content to the response after this chain has executed
        //response.getWriter().write("<!-- Written from the Sample Sling Filter AFTER the next include -->");
    }  else {
        chain.doFilter(request, response);
    }
}
 
开发者ID:Adobe-Consulting-Services,项目名称:acs-aem-samples,代码行数:40,代码来源:SampleSlingRequestFilter.java

示例5: sendRedirectToOriginalRendition

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
private static void sendRedirectToOriginalRendition(SlingHttpServletRequest request, SlingHttpServletResponse response, Asset asset) throws IOException {
	String requestURL = request.getRequestURL().toString();
	String path = asset.getPath();
	String ext = getExtension(asset.getMimeType());
	String redirect = path + "." + SELECTOR_RENDITION_ORIGINAL + "." + ext;
	
	log.warn("Requested {}, however, rendition not found. Redirecting to {}", requestURL, redirect);
	response.sendRedirect(redirect);
}
 
开发者ID:HeroDigital,项目名称:renditions-servlet,代码行数:10,代码来源:ImageRenditionServlet.java

示例6: sendRedirectToProperExtension

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
private static void sendRedirectToProperExtension(SlingHttpServletRequest request, SlingHttpServletResponse response, Rendition rendition, RenditionMeta renditionMeta) throws IOException {
	String requestURL = request.getRequestURL().toString();
	String requestExt = request.getRequestPathInfo().getExtension();
	String newExt = getExtension(rendition.getMimeType());
	String redirect = requestURL;
	redirect = redirect.replaceAll(requestExt+"$", newExt);
	
	log.warn("Requested {}, however, mime type of rendition is {}. Redirecting to {}", requestURL, rendition.getMimeType(), redirect);
	response.sendRedirect(redirect);
}
 
开发者ID:HeroDigital,项目名称:renditions-servlet,代码行数:11,代码来源:ImageRenditionServlet.java

示例7: doPost

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
	
	resourceResolver = request.getResourceResolver();
	
	// Grab our params from the request.
	final String redirectPath = request.getParameter(":redirect");
	final String month = request.getParameter("month");
	final String yearString = request.getParameter("year");
	final Long year = Long.parseLong(yearString);
	
	// Get and fix the double value coming from Coral's Step Counter
	Double percent = Double.parseDouble(request.getParameter("percent"));
	DecimalFormat df = new DecimalFormat("###.##");
	df.setRoundingMode(RoundingMode.HALF_EVEN);
	percent = Double.parseDouble(df.format(percent));
	
	// Concat to create a semi-unique name
	final String nodeName = yearString + "-" + month;
	
	// Set properties for the entry.
	Map<String,Object> properties = new HashMap<String,Object>();
	properties.put(JcrConstants.JCR_PRIMARYTYPE, JcrConstants.NT_UNSTRUCTURED);
	properties.put("month", month);
	properties.put("year", year);
	properties.put("percent", percent);
	
	// Get our parent resource
	Resource parentResource = getParentResouce();
	
	// Try to get the existing node
	String existingPath = UPTIME_CALENDAR_PATH + "/" + nodeName;
	Resource uptimeEntry = resourceResolver.getResource(existingPath);
	
	if (uptimeEntry != null) {
		LOGGER.info("Saving existing uptime entry.");
		ModifiableValueMap existingProperties = uptimeEntry.adaptTo(ModifiableValueMap.class);
		existingProperties.putAll(properties);
		setMixin(uptimeEntry, NodeType.MIX_LAST_MODIFIED);
	} else {
		LOGGER.info("Creating New Uptime Entry.");
		uptimeEntry = resourceResolver.create(parentResource, nodeName, properties);
		setMixin(uptimeEntry, NodeType.MIX_CREATED);
	}
	
	resourceResolver.commit();
	resourceResolver.close();
	
	response.sendRedirect(redirectPath);
	
	// If you prefer a JSON response, uncomment this.
	//sendResponse(response, 200, "success", "Item has been updated");
	
}
 
开发者ID:auniverseaway,项目名称:aem-touch-admin-console,代码行数:55,代码来源:UptimeEntryServlet.java

示例8: doGet

import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
		throws ServletException, IOException {
	String fileName = request.getParameter("filename");
	String filePath = request.getParameter("filepath");

	String mode = request.getParameter("mode");

	try {
		final ResourceResolver resourceResolver = request.getResourceResolver();
		final Session session = resourceResolver.adaptTo(Session.class);

		if (!("view").equals(mode)) {
			response.setContentType("application/octet-stream"); // Your content type
			response.setHeader("Content-Disposition",
					"attachment; filename=" + URLEncoder.encode(fileName, "UTF-8"));
		}

		String path = StringUtils.replace(filePath, "_jcr_content", "jcr:content");

		Node jcrContent = session.getNode(path + "/jcr:content");

		InputStream input = jcrContent.getProperty("jcr:data").getBinary().getStream();

		session.save();
		int read;
		byte[] bytes = new byte[BYTES_DOWNLOAD];
		OutputStream os = response.getOutputStream();

		while ((read = input.read(bytes)) != -1) {
			os.write(bytes, 0, read);
		}
		input.close();
		os.flush();
		os.close();

	} catch (RepositoryException e) {
		LOGGER.error(e.getMessage(), e);
		response.sendRedirect("/etc/cqsm.html");
		// response.sendError(500);
	}
}
 
开发者ID:Cognifide,项目名称:APM,代码行数:43,代码来源:ScriptDownloadServlet.java


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