本文整理汇总了Java中org.apache.sling.api.SlingHttpServletResponse.setCharacterEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java SlingHttpServletResponse.setCharacterEncoding方法的具体用法?Java SlingHttpServletResponse.setCharacterEncoding怎么用?Java SlingHttpServletResponse.setCharacterEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.sling.api.SlingHttpServletResponse
的用法示例。
在下文中一共展示了SlingHttpServletResponse.setCharacterEncoding方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException
{
final Timer.Context t = metrics.timer(getClass().getSimpleName()).time();
try {
// Output the count of our child nodes
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
final PrintWriter w = response.getWriter();
w.print(request.getResource().getPath());
w.print(" has ");
w.print(countChildren(request.getResource(), ID));
w.print(" descendant nodes with an '");
w.print(ID);
w.print("' property. Sling instance ID is ");
w.print(settings.getSlingId());
w.println(".");
w.flush();
} finally {
t.stop();
}
}
示例2: doPost
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException
{
final Timer.Context t = metrics.timer(getClass().getSimpleName()).time();
try {
final String id = UUID.randomUUID().toString();
Resource r = request.getResource();
final Map<String, Object> props = new HashMap<String, Object>();
r = addChild(r, getClass().getSimpleName(), props);
for(int i=0 ; i < 4; i+=2) {
r = addChild(r, id.substring(i, i+2), props);
}
props.put(RootGetServlet.ID, id);
r = addChild(r, id, props);
r.getResourceResolver().commit();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/plain");
final PrintWriter w = response.getWriter();
w.print("Added ");
w.println(r.getPath());
w.flush();
} finally {
t.stop();
}
}
示例3: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
@Override
protected final void doGet(final SlingHttpServletRequest request, final SlingHttpServletResponse response)
throws ServletException, IOException {
LOG.info("Servlet GET Method requested");
// Write a standard text/html response
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.getWriter().write("<html><body>Text to write to response</body></html>");
}
示例4: doGet
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Add overrides for other SlingSafeMethodsServlet here (doGeneric, doHead, doOptions, doTrace) *
*/
@Override
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws
ServletException, IOException {
// Implement custom handling of GET requests
boolean responseIsText = true;
if (responseIsText) {
// Write a standard text/html response
response.setContentType("text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.getWriter().write("<html><body>Text to write to response</body></html>");
} else {
// Write some binary data to the response; Such as sending back an Image or PDF
InputStream input = new InputStream() {
@Override
public int read() throws IOException {
return 0;
}
};
response.setContentType(getServletContext().getMimeType(request.getPathInfo()));
OutputStream output = response.getOutputStream();
byte[] buffer = new byte[FOUR_KB];
for (int length = 0; (length = input.read(buffer)) > 0;) {
output.write(buffer, 0, length);
output.flush();
}
}
}
示例5: doPost
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Save system properties on POST.
*
* @param request The Sling HTTP servlet request.
* @param response The Sling HTTP servlet response.
*/
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
final PrintWriter writer = response.getWriter();
final boolean allowWrite = userService.isAuthorable(request.getResourceResolver().adaptTo(Session.class));
response.setCharacterEncoding(CharEncoding.UTF_8);
response.setContentType("application/json");
if (allowWrite) {
final String blogName = request.getParameter(BLOG_NAME_PROPERTY);
final boolean extensionlessUrls = Boolean.parseBoolean(request.getParameter(EXTENSIONLESS_URLS_PROPERTY));
final String tempDir = request.getParameter(TEMPORARY_DIRECTORY_PROPERTY);
final Map<String, Object> properties = new HashMap<String, Object>();
properties.put(SystemSettingsService.SYSTEM_BLOG_NAME, blogName);
properties.put(SystemSettingsService.SYSTEM_EXTENSIONLESS_URLS, extensionlessUrls);
properties.put(SystemSettingsService.SYSTEM_TEMPORARY_DIRECTORY, tempDir);
boolean result = systemSettingsService.setProperties(properties);
if (result) {
response.setStatus(SlingHttpServletResponse.SC_OK);
sendResponse(writer, "OK", "Settings successfully updated.");
} else {
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
sendResponse(writer, "Error", "Settings failed to update.");
}
} else {
response.setStatus(SlingHttpServletResponse.SC_FORBIDDEN);
sendResponse(writer, "Error", "Current user not authorized.");
}
}
示例6: writeJson
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
public static void writeJson(SlingHttpServletResponse response, String json) throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
response.getWriter().write(json);
response.getWriter().flush();
}
示例7: doPost
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Save email configuration on POST.
*
* @param request The Sling HTTP servlet request.
* @param response The Sling HTTP servlet response.
*/
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
throws ServletException, IOException {
final PrintWriter writer = response.getWriter();
final boolean allowWrite = userService.isAuthorable(request.getResourceResolver().adaptTo(Session.class));
response.setCharacterEncoding(CharEncoding.UTF_8);
response.setContentType("application/json");
if (allowWrite) {
final String smtpUsername = request.getParameter(SMTP_USERNAME_PROPERTY);
final String smtpPassword = request.getParameter(SMTP_PASSWORD_PROPERTY);
final String sender = request.getParameter(SENDER_PROPERTY);
final String recipient = request.getParameter(RECIPIENT_PROPERTY);
final String host = request.getParameter(HOST_PROPERTY);
final Long port = getPortNumber(request.getParameter(PORT_PROPERTY));
final Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EmailService.EMAIL_SMTP_USERNAME, smtpUsername);
properties.put(EmailService.EMAIL_SENDER, sender);
properties.put(EmailService.EMAIL_RECIPIENT, recipient);
properties.put(EmailService.EMAIL_SMTP_HOST, host);
properties.put(EmailService.EMAIL_SMTP_PORT, port);
/* Don't save the password if it's all stars. Don't save the password
* if the user just added text to the end of the stars. This shouldn't
* happen as the JavaScript should remove the value on focus. Save the
* password if it's null or blank in order to clear it out. */
if (smtpPassword == null || !smtpPassword.contains(PublickConstants.PASSWORD_REPLACEMENT)) {
properties.put(EmailService.EMAIL_SMTP_PASSWORD, smtpPassword);
}
final boolean result = emailService.setProperties(properties);
if (result) {
response.setStatus(SlingHttpServletResponse.SC_OK);
sendResponse(writer, "OK", "Settings successfully updated.");
} else {
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
sendResponse(writer, "Error", "Settings failed to update.");
}
} else {
response.setStatus(SlingHttpServletResponse.SC_FORBIDDEN);
sendResponse(writer, "Error", "Current user not authorized.");
}
}
示例8: doPost
import org.apache.sling.api.SlingHttpServletResponse; //导入方法依赖的package包/类
/**
* Save reCAPTCHA properties on POST.
*
* @param request The Sling HTTP servlet request.
* @param response The Sling HTTP servlet response.
*/
@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
final PrintWriter writer = response.getWriter();
final boolean allowWrite = userService.isAuthorable(request.getResourceResolver().adaptTo(Session.class));
response.setCharacterEncoding(CharEncoding.UTF_8);
response.setContentType("application/json");
if (allowWrite) {
final String siteKey = request.getParameter(SITE_KEY_PROPERTY);
final String secretKey = request.getParameter(SECRET_KEY_PROPERTY);
final boolean enabled = Boolean.parseBoolean(request.getParameter(ENABLED_PROPERTY));
final Map<String, Object> properties = new HashMap<String, Object>();
properties.put(RecaptchaService.RECAPTCHA_SITE_KEY, siteKey);
properties.put(RecaptchaService.RECAPTCHA_ENABLED, enabled);
/* Don't save the password if it's all stars. Don't save the password
* if the user just added text to the end of the stars. This shouldn't
* happen as the JavaScript should remove the value on focus. Save the
* password if it's null or blank in order to clear it out. */
if (StringUtils.isBlank(secretKey) || !secretKey.contains(PublickConstants.PASSWORD_REPLACEMENT)) {
properties.put(RecaptchaService.RECAPTCHA_SECRET_KEY, secretKey);
}
final boolean result = recaptchaService.setProperties(properties);
if (result) {
response.setStatus(SlingHttpServletResponse.SC_OK);
sendResponse(writer, "OK", "Settings successfully updated.");
} else {
response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
sendResponse(writer, "Error", "Settings failed to update.");
}
} else {
response.setStatus(SlingHttpServletResponse.SC_FORBIDDEN);
sendResponse(writer, "Error", "Current user not authorized.");
}
}