我在实现基于表单的身份验证时遇到了问题。我创建了一个简单的 Web 应用程序,在打开页面 (/jsp/index.jsp) 之前,我想检查用户的权限并在必要时打开一个登录页面。
不幸的是,如果我尝试打开 index.jsp 的链接(http://localhost:8080/mywebapp/jsp/index.jsp),index.jsp 会立即出现,但我希望先登录 login.jsp!以下是重要文件:
Shiro.ini
[main]
# specify login page
authc.loginUrl = /login.jsp
# name of request parameter with username; if not present filter assumes 'username'
authc.usernameParam = user
# name of request parameter with password; if not present filter assumes 'password'
authc.passwordParam = passw
# does the user wish to be remembered?; if not present filter assumes 'rememberMe'
authc.rememberMeParam = remember
[url]
# enable authc filter for all application pages
/jsp/** = authc
[users]
adminstrator=throttling,Administrator
web.xml
<web-app id="starter" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
</filter-mapping>
</web-app>
这是maven项目的目录结构/src/main
├───java
├───resources
│ log4j.properties
│ Shiro.ini
│
└───webapp
│ login.jsp
│
├───jsp
│ index.jsp
│
└───WEB-INF
│ web.xml
│
└───lib
我将这两个依赖项添加到 pom.xml
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-web</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
<version>1.2.1</version>
</dependency>
希望我写了任何重要的信息!谁能帮助我为什么它对我不起作用?谢谢,V。
log4j.properties
log4j.rootLogger=TRACE, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%c]: %m%n
log4j.logger.net.sf.ehcache=WARN
log4j.logger.org.apache=WARN
log4j.logger.org.quartz=WARN
log4j.logger.org.apache.shiro=TRACE
log4j.logger.org.apache.shiro.util.ThreadContext=INFO