【发布时间】:2012-10-13 01:32:59
【问题描述】:
我已经使用 Spring MVC、Restful webservices 为移动客户端实现了服务器后端。我想用弹簧安全保护应用程序。我已经放了一个自定义的 login.jsp 来处理登录,如下所示。
<body onload='document.f.j_username.focus();'>
<h3>Login with Username and Password (Custom Page)</h3>
<c:if test="${not empty error}">
<div class="errorblock">
Your login attempt was not successful, try again.<br /> Caused :
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
</div>
</c:if>
<form name='f' action="<c:url value='j_spring_security_check' />"
method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' />
</td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" />
</td>
</tr>
<tr>
<td colspan='2'><input name="reset" type="reset" />
</td>
</tr>
</table>
</form>
我的web.xml如下。
<display-name>Spring MVC Application</display-name>
<!-- Spring MVC -->
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/mvc-dispatcher-servlet.xml,
/WEB-INF/spring-security-context.xml
</param-value>
</context-param>
<!-- Spring Security -->
<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>
</filter-mapping>
spring-security-context.xml 如下。
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config="true">
<intercept-url pattern="/getHierarchy" access="ROLE_USER" />
<form-login login-page="/login" default-target-url="/getHierarchy"
authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="admin" password="admin" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
但我在 eclipse 上收到警告
在 Java 构建路径中找不到“c:if” (org.apache.taglibs.standard.tag.rt.core.IfTag) 的标记处理程序类
当我提交表单时,在 j_spring_security_check 上出现 not found 错误。我在类路径中包含了 jstl1.2。为什么即使我已包含 taglib,我也会收到未找到标记处理程序的警告?
【问题讨论】:
-
您是否发布了 COMPLETE
login.jsp或者您是否跳过了标题? -
是的,我跳过了标题...其中只有几个样式标签。仅此而已。 Taglib 声明如下。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -
您写道:
I have included jstl1.2 in the classpath.它到底包含在哪个文件夹中?例如\myProject\libs或\myProject\webapp\WEB-INF\lib? -
它在 \myProject\webapp\WEB-INF\lib 文件夹中
标签: spring spring-security taglib