protected boolean preTemplateProcess(Template template, TemplateModel model) throws IOException {
    Object attrContentType = template.getCustomAttribute("content_type");

    if (attrContentType != null) {
      ServletActionContext.getResponse().setContentType(attrContentType.toString());
    } else {
      String contentType = getContentType();

      if (contentType == null) {
        contentType = "text/html";
      }

      // webwork:
      //            String encoding = template.getEncoding();

      String encoding = template.getOutputEncoding();

      if (encoding != null) {
        contentType = contentType + "; charset=" + encoding;
      }

      ServletActionContext.getResponse().setContentType(contentType);
    }

    return true;
  }
 public void execute(ActionInvocation invocation) throws Exception {
   LatestVersionSource source = (LatestVersionSource) invocation.getAction();
   double latestVersion = source.getLatestVersion();
   HttpServletResponse response = ServletActionContext.getResponse();
   response.setContentType("text/xml");
   OutputStream out = response.getOutputStream();
   out.write(String.valueOf(latestVersion).getBytes());
   out.close();
 }
示例#3
0
 public void execute(ActionInvocation invocation) throws Exception {
   XmlProducer producer = (XmlProducer) invocation.getAction();
   XmlRenderable xmlRenderable = producer.getXmlRenderable();
   Element element = xmlRenderable.asXml();
   Document document = new Document(element);
   String xmlString = XmlUtility.asString(document);
   HttpServletResponse response = ServletActionContext.getResponse();
   response.setContentType("text/xml");
   try {
     OutputStream out = response.getOutputStream();
     BufferedOutputStream bufferedOut = new BufferedOutputStream(out);
     bufferedOut.write(xmlString.getBytes());
     bufferedOut.close();
   } catch (IOException e) {
     logger.warning("Failed to write result XML response to browser: " + e.toString());
   }
 }