简体   繁体   English

如何禁用未在pretty-config.xml中映射的所有URI

[英]How to disable all URIs which are not mapped in pretty-config.xml

I want to whenever user types in address bar uri which isn't mapped in my pretty-config.xml file to get 404 error. 我希望每当用户在地址栏中输入uri时,我的pretty-config.xml文件中没有映射到404错误。 My pretty-config looks like: 我的漂亮配置看起来像:

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

For example when user types myapp.com/faces/login.xhtml application should return 404 error. 例如,当用户键入myapp.com/faces/login.xhtml时,应该返回404错误。 How to do that? 怎么做?

I'd recommend using Rewrite ( https://www.ocpsoft.org/rewrite ) for this. 我建议使用Rewrite( https://www.ocpsoft.org/rewrite )。 It's already included in your project with PrettyFaces: 它已经包含在您的PrettyFaces项目中:

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(".*");
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以用注释替换pretty-config.xml配置吗 - Can I replace pretty-config.xml configuration with annotations 如果faces-config.xml中没有导航用例,如何禁用命令按钮 - How disable commandbutton if there is no navigation-case in faces-config.xml 使用pretty-config重写URL - Rewriting URLs using pretty-config 如何将注释与faces-config.xml混合使用 - How to mix annotations with faces-config.xml 如何配置faces-config.xml - How to configure the faces-config.xml 如何在PrimeFaces dataTable列中使用换行符(漂亮打印)显示XML内容? - How do you display XML content with line feeds (pretty print) in a PrimeFaces dataTable column? 如何在将web.xml映射到.html而不是.jsf的同时上传文件JSF 2.0? - How to upload a file JSF 2.0 while having web.xml mapped to .html instead of .jsf? 漂亮的面孔配置WebSphere Application Server上的问题 - JSF2 - Pretty faces config issues on WebSphere Application server - JSF2 使用web.xml和pretty-faces重定向到自定义错误页面 - Redirecting to custom error page with web.xml and pretty-faces 无法将文件验证为XML定义,如何解决faces-config.xml警告? - File cannot be validated as the XML Definition, How to fix faces-config.xml warning?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM