我试图使用Spring安全性,但现在我找不到问题所在。 现在我无法找到为什么这个/ j_spring_security_login没有链接到登录页面。
<a href="<c:url value='/j_spring_security_login'/>"><button>로그인</button></a>
我希望在点击此链接时转到/登录页面,但只显示404页面。 我的web.xml就像这样
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-security.xml
/WEB-INF/repository.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
和spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/beans"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<sec:http auto-config="true" use-expressions="true">
<sec:intercept-url pattern="/admin/**" access="hasAuthority('ROLE_ADMIN')"/>
<sec:intercept-url pattern="/account/**" access="hasAuthority('ROLE_USER')"/>
<sec:intercept-url pattern="/**" access="permitAll"/>
<sec:form-login
login-page="/login"
default-target-url="/welcom"
authentication-failure-url="/login?error"/>
<sec:logout logout-url="/login?logout" />
</sec:http>
<sec:authentication-manager>
<sec:authentication-provider>
<!-- <jdbc-user-service data-source-ref="dataSource"
users-by-username-query="SELECT username, password, enabled FROM USER WHERE username = ?"
authorities-by-username-query="SELECT username, role FROME USER_ROLE WHERE username = ?" /> -->
<sec:user-service>
<sec:user name="admin" password="admin" authorities="ROLE_USER" />
</sec:user-service>
</sec:authentication-provider>
</sec:authentication-manager>
</beans:beans>
抱歉我的英语不好。如果您愿意,这是我的github page