首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用漂亮-config.xml中未映射的所有URI

如何禁用漂亮-config.xml中未映射的所有URI
EN

Stack Overflow用户
提问于 2018-05-22 14:38:01
回答 1查看 73关注 0票数 1

每当用户输入地址栏uri时,我都想输入它,它没有映射到我的漂亮-config.xml文件中,以获得404错误。我的漂亮配置看起来像:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.org/schema/rewrite-config-prettyfaces" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xsi:schemaLocation="http://ocpsoft.org/schema/rewrite-config-prettyfaces>

<url-mapping id="landing">
    <pattern value="/" />
    <view-id value="/faces/index.xhtml" />
</url-mapping>

<url-mapping id="login">
    <pattern value="/login" />
    <view-id value="/faces/login.xhtml" />
</url-mapping>

</pretty-config>

例如,当用户键入myapp.com/faces/login.xhtml应用程序时,应该返回404错误。怎么做?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-05-23 14:28:23

为此,我建议使用重写(https://www.ocpsoft.org/rewrite)。它已经包含在您的PrettyFaces项目中:

代码语言:javascript
复制
package com.example;

@RewriteConfiguration
public class ExampleConfigurationProvider extends HttpConfigurationProvider
{
   @Override
   public int priority()
   {
     return 10000000; // Very large priority # should occur last.
   }

   @Override
   public Configuration getConfiguration(final ServletContext context)
   {
     return ConfigurationBuilder.begin()
       .addRule()
         .when(
            // filter inbound requests only
            Direction.isInbound()
            // match all paths
            .and(Path.matches("/{p}"))
            // only catch requests if they were not already internally forwarded by another rule
            .and(Not.any(DispatchType.isForward())) 
         )
         // Show the 404 page.
         .perform(Forward.to("/404"))
         // Allow "p" to match any URL path
         .where("p").matches(".*");
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50470423

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档