コード例 #1
0
ファイル: ServletFree.java プロジェクト: yixuanwang26/JspExam
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   Map root = new HashMap();
   Connection conn = null;
   conn = ConFact.getInstance().makeConnection();
   String id = req.getParameter("id");
   String sql = "select title,description,language_id from film where film_id=" + id + ";";
   java.sql.PreparedStatement pst;
   try {
     pst = conn.prepareStatement(sql);
     ResultSet rs = pst.executeQuery();
     while (rs.next()) {
       java.sql.PreparedStatement pst1;
       String sql1 = "select name from language where language_id=" + rs.getString(3) + ";";
       pst1 = conn.prepareStatement(sql1);
       ResultSet rs1 = pst1.executeQuery();
       while (rs1.next()) {
         Template t = cfg.getTemplate("test.ftl");
         root.put("title", rs.getString(1));
         root.put("description", rs.getString(2));
         root.put("language", rs1.getString(1));
         resp.setContentType("text/html; charset=" + t.getEncoding());
         Writer out = resp.getWriter();
         t.process(root, out);
       }
       rs1.close();
     }
     rs.close();
     pst.close();
     conn.close();
   } catch (TemplateException e) {
     e.printStackTrace();
   } catch (SQLException e1) {
     e1.printStackTrace();
   }
 }
コード例 #2
0
  /**
   * Sets the settings of the {@link Template} which are not yet set in the {@link Template} and are
   * set in this {@link TemplateConfigurer}, leaves the other settings as is. A setting is said to
   * be set in a {@link TemplateConfigurer} or {@link Template} if it was explicitly set via a
   * setter method on that object, as opposed to be inherited from the {@link Configuration}.
   *
   * <p>Note that the {@code encoding} setting of the {@link Template} counts as unset if it's
   * {@code null}, even if {@code null} was set via {@link Template#setEncoding(String)}.
   *
   * @throws IllegalStateException If the parent configuration wasn't yet set.
   */
  public void configure(Template template) {
    checkParentConfigurationSet();
    Configuration cfg = getParentConfiguration();
    if (template.getConfiguration() != cfg) {
      // This is actually not a problem right now, but for future BC we enforce this.
      throw new IllegalArgumentException(
          "The argument Template doesn't belong to the same Configuration as the TemplateConfigurer");
    }

    if (isAPIBuiltinEnabledSet() && !template.isAPIBuiltinEnabledSet()) {
      template.setAPIBuiltinEnabled(isAPIBuiltinEnabled());
    }
    if (isArithmeticEngineSet() && !template.isArithmeticEngineSet()) {
      template.setArithmeticEngine(getArithmeticEngine());
    }
    if (isAutoFlushSet() && !template.isAutoFlushSet()) {
      template.setAutoFlush(getAutoFlush());
    }
    if (isBooleanFormatSet() && !template.isBooleanFormatSet()) {
      template.setBooleanFormat(getBooleanFormat());
    }
    if (isClassicCompatibleSet() && !template.isClassicCompatibleSet()) {
      template.setClassicCompatibleAsInt(getClassicCompatibleAsInt());
    }
    if (isDateFormatSet() && !template.isDateFormatSet()) {
      template.setDateFormat(getDateFormat());
    }
    if (isDateTimeFormatSet() && !template.isDateTimeFormatSet()) {
      template.setDateTimeFormat(getDateTimeFormat());
    }
    if (isEncodingSet() && template.getEncoding() == null) {
      template.setEncoding(getEncoding());
    }
    if (isLocaleSet() && !template.isLocaleSet()) {
      template.setLocale(getLocale());
    }
    if (isLogTemplateExceptionsSet() && !template.isLogTemplateExceptionsSet()) {
      template.setLogTemplateExceptions(getLogTemplateExceptions());
    }
    if (isNewBuiltinClassResolverSet() && !template.isNewBuiltinClassResolverSet()) {
      template.setNewBuiltinClassResolver(getNewBuiltinClassResolver());
    }
    if (isNumberFormatSet() && !template.isNumberFormatSet()) {
      template.setNumberFormat(getNumberFormat());
    }
    if (isObjectWrapperSet() && !template.isObjectWrapperSet()) {
      template.setObjectWrapper(getObjectWrapper());
    }
    if (isOutputEncodingSet() && !template.isOutputEncodingSet()) {
      template.setOutputEncoding(getOutputEncoding());
    }
    if (isShowErrorTipsSet() && !template.isShowErrorTipsSet()) {
      template.setShowErrorTips(getShowErrorTips());
    }
    if (isSQLDateAndTimeTimeZoneSet() && !template.isSQLDateAndTimeTimeZoneSet()) {
      template.setSQLDateAndTimeTimeZone(getSQLDateAndTimeTimeZone());
    }
    if (isTemplateExceptionHandlerSet() && !template.isTemplateExceptionHandlerSet()) {
      template.setTemplateExceptionHandler(getTemplateExceptionHandler());
    }
    if (isTimeFormatSet() && !template.isTimeFormatSet()) {
      template.setTimeFormat(getTimeFormat());
    }
    if (isTimeZoneSet() && !template.isTimeZoneSet()) {
      template.setTimeZone(getTimeZone());
    }
    if (isURLEscapingCharsetSet() && !template.isURLEscapingCharsetSet()) {
      template.setURLEscapingCharset(getURLEscapingCharset());
    }

    copyDirectCustomAttributes(template, false);
  }