⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 macroview.java

📁 java servlet编程源码
💻 JAVA
字号:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.webmacro.*;
import org.webmacro.servlet.*;
import org.webmacro.engine.*;
import org.webmacro.broker.*;

// Extending com.oreilly.servlet.CacheHttpServlet can improve response time

public class MacroView extends HttpServlet {

  WebMacro wm;  // WebMacro main hook

  public void init() throws ServletException {
    try {
      wm = new WM();
    }
    catch (InitException e) {
      throw new ServletException(e);
    }
  }

  public void doGet(HttpServletRequest req, HttpServletResponse res)
                               throws ServletException, IOException {
    FastWriter out = new FastWriter(res.getOutputStream(),
                                    res.getCharacterEncoding());

    // The template name comes as extra path info
    //   /servlet/MacroView/templ.wm
    // or as servlet path via a *.wm rule
    //   /templ.wm
    String template = req.getPathInfo();
    if (template == null) {
      template = req.getServletPath();
      template = template.substring(1);  // cut off leading "/"
    }

    // If template is still null, we have a problem
    if (template == null) {
      throw new ServletException(
        "No template specified as extra path info or servlet path");
    }

    try {
      Template tmpl = wm.getTemplate(template);
      WebContext context = wm.getWebContext(req, res); 
      tmpl.write(out, context);
    }
    catch (WebMacroException e) {
      throw new ServletException(e);
    }
    finally {
      out.flush();
    }
  }

  public void destroy() {
    super.destroy();
    if (wm != null) wm.destroy();
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -