微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐