当我介绍 Apache SHIRO 时,为啥 .XHTML 文件试图调用 .JSP 文件?

Posted

技术标签:

【中文标题】当我介绍 Apache SHIRO 时,为啥 .XHTML 文件试图调用 .JSP 文件?【英文标题】:Why Is .XHTML file trying to call .JSP file when i introduce Apache SHIRO?当我介绍 Apache SHIRO 时,为什么 .XHTML 文件试图调用 .JSP 文件? 【发布时间】:2018-12-29 18:15:43 【问题描述】:

我有一个严重的问题。 我有一个带有框架 primefaces 的 JSF 项目。当我在没有 Apache shiro 的 netbeans 中运行项目时,它会将我重定向到 login.xhtml。但是一旦在 web.xml 中引入了 shiro 配置

<listener>
    <listenerclass>
        org.apache.shiro.web.env.EnvironmentLoaderListener
    </listener-class>
</listener>
<filter>
    <filter-name>ShiroFilter</filter-name>
    <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>ShiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
    <dispatcher>ERROR</dispatcher>
</filter-mapping>

Neatbeans 将我重定向到 login.jsp。 这是我的 shiro.ini 文件

[main]
#le chemin de la classe "FacesAjaxAwareUserFilter" et celuii de la page qui va s'afficher si l'uthentification ne marche pas et la page qui s'affichera si ca marche
user = com.soulsofts.atmosphere.web.utils.shiro.FacesAjaxAwareUserFilter
#authc.loginUrl = /login.xhtml
#authc.successUrl = /index.xhtml

#;l'id de de la form du login et les different champs 
authc.usernameParam = login:username
authc.passwordParam = login:password
authc.rememberMeParam = login:rememberMe

#;le nom de la classe qui contien les configurations
entityRealm =  com.soulsofts.atmosphere.web.utils.shiro.EntityRealm

#authentif = com.soulsofts.atmosphere.core.entities.User
#;cette partie contient le nom des utilisateur qui ne seront pas verifier l'or de l'authentification
[users]
njjjjj=njjjjj

#;permet de definir les URL qui on besoin d'athentification avant de pouvoir y acceder
#;anon= pour dire que cette page n'aura pas besoin d'authentification
#;authc=pour dire que cette page en aura besoin
[urls]
/javax.faces.resource/** = anon
/resources/** = anon
/WEB-INF/** = anon
/login.xhtml = anon
/access-denied.xhtml = anon
/error.xhtml = anon
/404.xhtml = anon
/empty-page.xhtml = anon
/access-denied.xhtml = anon
/** = authc

这是 web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>verona-turquoise</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.FONT_AWESOME</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
        <param-value>/WEB-INF/primefaces-verona.taglib.xml</param-value>
    </context-param>
    <filter>
        <filter-name>Character Encoding Filter</filter-name>
        <filter-class>com.soulsofts.atmosphere.web.veronaComponent.CharacterEncodingFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Character Encoding Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <mime-mapping>
        <extension>ttf</extension>
        <mime-type>application/font-sfnt</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>woff</extension>
        <mime-type>application/font-woff</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>woff2</extension>
        <mime-type>application/font-woff2</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>eot</extension>
        <mime-type>application/vnd.ms-fontobject</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>eot?#iefix</extension>
        <mime-type>application/vnd.ms-fontobject</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exosemibold</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exobolditalic</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exomedium</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#exoregular</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>svg#fontawesomeregular</extension>
        <mime-type>image/svg+xml</mime-type>
    </mime-mapping>
    <listener>
        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>ShiroFilter</filter-name>
        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ShiroFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>
</web-app>

你能帮我解决这个问题吗?

【问题讨论】:

您好,很抱歉打扰您,这是一个评论问题。我在阅读我的帖子时评论了它。在 shiro.ini 文件中,我评论了这两行 #authc.loginUrl = /login.xhtml #authc.successUrl = /index.xhtml 我通过删除评论标签来解决它。但为什么它会将我重定向到 login.jsp 文件? 【参考方案1】:

如果未指定,则 URL login.jsp 是 Shiro 默认页面。您必须使用 authc.loginUrl,如下所示...

authc.loginUrl = /login.xhtml

你的帖子在上面的帖子中被评论了。

【讨论】:

嗨@Melloware。感谢您的回答。它有帮助

以上是关于当我介绍 Apache SHIRO 时,为啥 .XHTML 文件试图调用 .JSP 文件?的主要内容,如果未能解决你的问题,请参考以下文章

转Apache shiro集群实现 shiro入门介绍

将 Struts 2 与 Apache Shiro 集成时如何显示结果页面

Apache Shiro 使用手册Shiro架构介绍

Apache Shiro 使用手册Shiro架构介绍

在 apache shiro 上为主题添加信息

Apache Shiro权限框架理论介绍