【问题标题】:How to deploy static web app to custom folder in IntelliJ IDEA?如何将静态 Web 应用程序部署到 IntelliJ IDEA 中的自定义文件夹?
【发布时间】:2015-04-15 05:37:25
【问题描述】:

在我的静态 Web 应用程序中,如果我从 IntelliJ IDEA 打开 index.html,则该项目是从

http://localhost:port/{project-name}/{folder-name}/index.html

是否可以将此路径配置为类似的东西?

http://localhost:port/{custom-folder}/index.html

【问题讨论】:

    标签: java jsp intellij-idea url-rewriting intellij-14


    【解决方案1】:

    1. 在下面添加 Maven 依赖或将 urlrewritefilter-4.0.3.jar 直接添加到您的 WEB-INF/lib 目录中。

    <dependency>
        <groupId>org.tuckey</groupId>
        <artifactId>urlrewritefilter</artifactId>
        <version>4.0.3</version>
    </dependency>
    

    2.将以下内容添加到您的WEB-INF/web.xml

    <filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>
    

    3.urlrewrite.xml 添加到您的WEB-INF 目录中。 (src/main/webapp/WEB-INF/ Maven 用户)

    <?xml version="1.0" encoding="utf-8"?>
    
    <!DOCTYPE urlrewrite
        PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
        "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
    
    <urlrewrite>
    
        <rule>
           <from>/{custom-folder}/index.html</from>
           <to type="redirect">/{project-name}/{folder-name}/index.html</to>
        </rule>
    
    </urlrewrite>
    

    4.重新启动,重新部署应用程序

    您可以访问http://127.0.0.1:8080/rewrite-status(或任何本地 web 应用程序的地址和上下文)查看输出(注意:此页面只能从本地主机查看)。

    试试http://localhost:port/{project-name}/{folder-name}/index.html

    参考:http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/4.0/index.html

    【讨论】:

    • 嗯,我不使用maven,我想配置默认的网络服务器来自Intellij Idea
    • 您的网络服务器及其版本是什么,您的编程语言是什么? (我猜是Java,但如果你使用IntelliJ IDEA,它可能是Scala或Groovy)
    • 我说的是 Intellij 的内置网络服务器,我的网络应用程序是静态的(html,javascript,css)
    • 当你在内置的网络服务器上测试时,你仍然必须将网页内容部署到一个真实的网络服务器上,然后我们通常使用 URL_Rewrite 技术来做你想做的事。对于 html、css 等静态内容的测试,我认为您不需要重写 URL。使用 Apache httpd 网络服务器,创建如下虚拟主机:httpd.apache.org/docs/2.2/vhosts/examples.html。这可能就是您所说的:jetbrains.com/idea/help/php-built-in-web-server.html
    • 谢谢老兄,这就是我所说的,你知道我在 Intellij Idea 上下文中到底需要改变什么吗!
    猜你喜欢
    • 2014-02-05
    • 1970-01-01
    • 1970-01-01
    • 2013-09-04
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2017-09-27
    相关资源
    最近更新 更多