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


Java Template.setOutputEncoding方法代碼示例

本文整理匯總了Java中freemarker.template.Template.setOutputEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java Template.setOutputEncoding方法的具體用法?Java Template.setOutputEncoding怎麽用?Java Template.setOutputEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在freemarker.template.Template的用法示例。


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

示例1: genHTML

import freemarker.template.Template; //導入方法依賴的package包/類
/**
	 * Processes the specified FreeMarker template with the specified request,
	 * data model.
	 *
	 * @param request
	 *            the specified request
	 * @param dataModel
	 *            the specified data model
	 * @param template
	 *            the specified FreeMarker template
	 * @return generated HTML
	 * @throws Exception
	 *             exception
	 */
	protected String genHTML(final HttpServletRequest request, final Map<String, Object> dataModel,
			final Template template) throws Exception {
		final StringWriter stringWriter = new StringWriter();

		template.setOutputEncoding("UTF-8");
		template.process(dataModel, stringWriter);

		final StringBuilder pageContentBuilder = new StringBuilder(stringWriter.toString());

		final long endimeMillis = System.currentTimeMillis();
		final String dateString = DateFormatUtils.format(endimeMillis, "yyyy/MM/dd HH:mm:ss");
//		final long startTimeMillis = (Long) request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS);
		final long startTimeMillis = System.currentTimeMillis();
		final String msg = String.format("<!-- Generated by B3log Latke(%1$d ms), %2$s -->",
				endimeMillis - startTimeMillis, dateString);

		pageContentBuilder.append(msg);

		return pageContentBuilder.toString();
	}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:35,代碼來源:AbstractFreeMarkerRenderer.java

示例2: render

import freemarker.template.Template; //導入方法依賴的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);
		}
	}
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:29,代碼來源:IndexProcessor.java


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