每当用户输入地址栏uri时,我都想输入它,它没有映射到我的漂亮-config.xml文件中,以获得404错误。我的漂亮配置看起来像:
<?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错误。怎么做?
发布于 2018-05-23 14:28:23
为此,我建议使用重写(https://www.ocpsoft.org/rewrite)。它已经包含在您的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(".*");
}
}https://stackoverflow.com/questions/50470423
复制相似问题