需求:login.ftl页面中登录成功后进入index.ftl页面中
一、pom.xml中添加json转换相关的包
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>2.4.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.4.4</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>2.4.4</version>
- </dependency>
二、applicationContext-mvc.xml中添加json转换相关的配置
- <!--token 拦截校验 -->
- <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
- <bean id="contentNegotiationManager" class="org.springframework.web.accept.ContentNegotiationManagerFactoryBean">
- <property name="favorPathExtension" value="false" />
- <property name="favorParameter" value="true" />
- <property name="ignoreAcceptHeader" value="false" />
- <property name="mediaTypes">
- <value>
- atom=application/atom+xml
- html=text/html
- json=application/json
- *=*/*
- </value>
- </property>
- </bean>
三、applicationContext-security.xml中
将<intercept-url pattern="/service/index/index"access="ROLE_AUTHORITY"/>
改为<intercept-url pattern="/service/index/index" />
这里只是要实现简单的登录功能,所以没有设计权限。加了access=” "ROLE_AUTHORITY”会导致无法登录。
四、实现效果