加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – Eclipse JSP预览

发布时间:2020-12-15 01:30:16 所属栏目:大数据 来源:网络整理
导读:是否有允许预览JSP文件的Eclipse插件或功能?理想情况下,这样的功能会识别Spring标签.在Eclipse中编辑JSP,然后构建和部署以查看结果是一个很大的痛苦. 最佳答案 我还没有看到任何能够满足您要求的好插件. 作为替代方案,您可以将jetty服务器的jar放到类路径中

是否有允许预览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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读