如何在IntelliJ IDEA中将静态Web应用程序部署到自定义文件夹?

问题描述 投票:1回答:1

在我的静态Web应用程序中,如果我从IntelliJ IDEA中打开index.html ,则可以从

http:// localhost:port / {项目名称} / {文件夹名称} /index.html

是否可以将此路径配置为类似这样的格式?

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

java jsp intellij-idea url-rewriting intellij-14
1个回答
0
投票

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应用程序的任何地址和上下文)以查看输出(请注意:此页面只能在localhost上查看)。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.