java – Eclipse JSP预览

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

最佳答案
我还没有看到任何能够满足您要求的好插件.

作为替代方案,您可以将jetty服务器的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

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...