【问题标题】:Eclipse JSP previewEclipse JSP 预览
【发布时间】:2010-10-19 11:47:47
【问题描述】:

是否有允许预览 JSP 文件的 Eclipse 插件或功能?理想情况下,这样的功能会意识到 Spring 标签。在 Eclipse 中编辑 JSP,然后构建和部署以查看结果是一件很痛苦的事情。

【问题讨论】:

    标签: java eclipse spring jsp


    【解决方案1】:

    我还没有看到任何可以满足您要求的好插件。

    作为替代方案,您可以将码头服务器的 jar 放入您的类路径(我使用 jetty-6.1.5.jar 和 jetty-util-6.1.5.jar)并编写如下所示的类。

    package net.eduportal.jetty;
    
    import javax.servlet.ServletContext;
    
    import org.mortbay.jetty.Server;
    import org.mortbay.jetty.security.UserRealm;
    import org.mortbay.jetty.webapp.WebAppContext;
    
    public class JettyRunner {
        public static final int PORT = 8080;
        public static final String BASE_URL = "http://localhost:" + PORT;
    
        private static final JettyRunner _instance = new JettyRunner();
    
        public static JettyRunner getInstance() {
            return _instance;
        }
    
        // ///////////////////////////////////////////////////////////////
        // Singleton
        // /////////////
    
        private Server server = null;
        private WebAppContext wac = null;
    
        private JettyRunner() {
        }
    
        public interface WebApplicationInitializer {
    
            public void init(WebAppContext wac);
    
        }
    
        public ServletContext getServletContext() {
            return wac.getServletContext();
        }
    
        public void start() throws Exception {
            if (server == null) {
                server = new Server(PORT);
                server.setStopAtShutdown(true);
                wac = new WebAppContext();
                wac.setContextPath("/test");
                wac.setResourceBase("war");
                wac.setClassLoader(this.getClass().getClassLoader());
                server.addHandler(wac);
                server.start();
            }
        }
    
        public void stop() throws Exception {
            if (server != null) {
                server.stop();
                server = null;
            }
        }
    
        public static void main(String argv[]) throws Exception {
            JettyRunner.getInstance().start();
        }
    
    }
    

    以上代码假设类路径中有一个名为“war”的文件夹,其中包含相同的 WEB-INF/* 文件夹。当您从 eclipse 运行代码时,服务器将启动,您可以通过访问位置 localhost:8080/test/* 来查看 jsps

    http://jetty.mortbay.org/jetty5/tut/Server.html

    【讨论】:

      【解决方案2】:

      您根本不必重建即可看到结果。

      最新的 Eclipse 企业版实际上对 JSP 进行了热代码替换。我将 Web 项目添加到 Tomcat(或 Glassfish 或 JBoss...),我在 JSP 中所做的任何更改都会在我刷新浏览器窗口后反映出来。显然,当我更改一个Java文件时,我需要重新启动Tomcat,但最多只需要2秒。

      【讨论】:

        【解决方案3】:

        MyEclipse 提供了这个插件:

        http://www.myeclipseide.com/module-htmlpages-display-pid-11.html

        至于它是否支持 Spring 标签是另一回事......

        【讨论】:

          【解决方案4】:

          JBoss Tools (http://jboss.org/tools) 有一个支持 JSP、HTML 甚至 JSF 的可视化页面编辑器。

          如果标签不受支持,您可以右键单击它并为其添加模板,或者您可以通过实现扩展点来扩展支持的标签。

          扩展受支持标签集的用户示例为 http://relation.to/Bloggers/HowToCreateAVisualDocBookEditorIn10Minuteshttp://planetjbpm.wordpress.com/2009/02/25/xforms-editor-with-jboss-vpe-and-some-jbpm/

          【讨论】:

            【解决方案5】:

            Oracle Workshop for WebLogic 10g R3 为您提供最接近所见即所得 JSP 编辑的东西。尽管它来自 Oracle/BEA,但它可以与许多应用服务器一起使用,而不仅仅是 WebLogic。它是我所知道的用于 JSP 的最佳工具,而且它是免费的。我不关心 Spring 标签,但可以对其进行定制以提供标签的设计时间表示。我不确定他们是否支持 Eclipse 3.4。

            还有JBoss Developer Studio 有很好的JSP 可视化工具。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-03-17
              • 1970-01-01
              • 2010-09-20
              • 2014-01-27
              • 1970-01-01
              相关资源
              最近更新 更多