Eclipse JSP预览

Ste*_*Kuo 7 java eclipse spring jsp

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

Jer*_*ese 1

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

作为替代方案,您可以将 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();
    }

}
Run Code Online (Sandbox Code Playgroud)

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

请参阅http://jetty.mortbay.org/jetty5/tut/Server.html