zoukankan      html  css  js  c++  java
  • Wildfly 和第三方 UrlRewrite

    资源

    UrlRewrite概念可参考: http://blog.csdn.net/crazy1235/article/details/8585310

    UrlRewrite第三方库: http://tuckey.org/urlrewrite/

    WildFly下载: http://wildfly.org/downloads/

    安装及相关配置

    1. Ubuntu下完成WildFly下载后执行"unzip wildfly-10.1.0.Final.zip"解压WildFly到当前目录,完成此步骤后可以根据需要移动WildFly到其他指定目录,并可修改目录名称比如"wildfly10".
    2. 进入"./wildfly/bin"并执行"add-user.sh"添加新用户,比如"admin",这个过程指定用户角色并不重要.
    3. 完成用户注册后,执行"standalone.sh"启动WildFly Application Server.
    4. 服务器启动后,缺省情况下访问:http://localhost:9990部署Web App,完成部署的应用从 http://localhost:8080访问.

    "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>

    要使用第三方UrlRewrite库则需要把"urlrewritefilter-4.0.3.jar"拷贝到Web App的"WEB-INF/lib",然后在"WEB-INF"下添加如下jboss-web.xml:

    <?xml version="1.0" encoding="UTF-8"?>
     <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
      http://www.jboss.com/xml/ns/javaee
      http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
      <context-root>/</context-root>
     </jboss-web>
    

    UrlRewrite规则定义在如下"WEB-INF/urlrewrite.xml"文件:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"  
    "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">  
    <urlrewrite>  
        <rule>  
            <from>/hello/abc/</from>  
            <to type="forward">/</to>  
        </rule>
        <rule>  
            <from>/hallo/</from>  
            <to type="forward">/</to>  
        </rule>
    </urlrewrite>

    完成部署和相关配置后,可以通过以下Urls访问部署的Web App:

    http://localhost:8080/
    
    http://localhost:8080/hello/abc/

    http://localhost:8080/hallo/

      

          

  • 相关阅读:
    python函数名和左括号之间不能有空格
    linux版本选择
    filter_map
    awk统计总结
    Spring Boot + Redis 实现各种操作
    手机号正则校验
    判断windows系统
    Redis分布式锁
    shell 脚本快速部署 SpringBoot 项目
    Java主流的Http请求--原生的HttpURLConnection
  • 原文地址:https://www.cnblogs.com/jinzd/p/7514216.html
Copyright © 2011-2022 走看看