-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HomePage interceptor and some refactoring done.
- Loading branch information
Showing
11 changed files
with
356 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../TwitMini/controller/AuthInterceptor.java → ...TwitMini/interceptor/AuthInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package TwitMini.interceptor; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
|
||
public class HomeInterceptor extends HandlerInterceptorAdapter { | ||
|
||
private final ThreadLocal<Long> userID; | ||
|
||
|
||
|
||
@Autowired | ||
public HomeInterceptor(@Qualifier("userID") ThreadLocal<Long> userID) { | ||
this.userID = userID; | ||
} | ||
|
||
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) | ||
throws Exception { | ||
|
||
HttpSession session = request.getSession(false); | ||
if (session != null) { | ||
String userName = (String) session.getAttribute("userName"); | ||
if (userName != null) { | ||
userID.set((Long) session.getAttribute("userID")); | ||
System.out.println("checking if homeinterceptor works, user id is "+ userID + request.getRequestURL()+" with value:"+userID.get()); | ||
response.sendRedirect("/home"); | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context-3.0.xsd | ||
http://www.springframework.org/schema/mvc | ||
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> | ||
|
||
<mvc:annotation-driven/> | ||
|
||
|
||
<context:component-scan base-package="TwitMini"/> | ||
|
||
<context:component-scan base-package="TwitMini.controller"/> | ||
<mvc:interceptors> | ||
<mvc:interceptor> | ||
<mvc:mapping path="/home/*"/> | ||
<mvc:mapping path="/home"/> | ||
<mvc:mapping path="/tweet"/> | ||
<mvc:mapping path="/tweet/*"/> | ||
<mvc:mapping path="/user/follow/*"/> | ||
<mvc:mapping path='/user/updates.json'/> | ||
<mvc:mapping path='/user/tweet/create.json'/> | ||
<mvc:mapping path='/user/{handle}/tweet/{id}/reply'/> | ||
<mvc:mapping path="/user/unfollow/*"/> | ||
<mvc:mapping path="/user/retweet/{id}"/> | ||
|
||
<bean class="TwitMini.controller.AuthInterceptor"/> | ||
</mvc:interceptor> | ||
</mvc:interceptors> | ||
|
||
|
||
|
||
|
||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | ||
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> | ||
<property name="prefix" value="/WEB-INF/jsp/"/> | ||
<property name="suffix" value=".jsp"/> | ||
</bean> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xmlns:mvc="http://www.springframework.org/schema/mvc" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans | ||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd | ||
http://www.springframework.org/schema/context | ||
http://www.springframework.org/schema/context/spring-context-3.0.xsd | ||
http://www.springframework.org/schema/mvc | ||
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> | ||
|
||
<mvc:annotation-driven/> | ||
|
||
|
||
<context:component-scan base-package="TwitMini"/> | ||
|
||
<context:component-scan base-package="TwitMini.controller"/> | ||
<mvc:interceptors> | ||
<mvc:interceptor> | ||
<mvc:mapping path="/home/*"/> | ||
<mvc:mapping path="/home"/> | ||
<mvc:mapping path="/tweet"/> | ||
<mvc:mapping path="/tweet/*"/> | ||
<mvc:mapping path="/user/follow/*"/> | ||
<mvc:mapping path='/user/updates.json'/> | ||
<mvc:mapping path='/user/tweet/create.json'/> | ||
<mvc:mapping path='/user/{handle}/tweet/{id}/reply'/> | ||
<mvc:mapping path="/user/unfollow/*"/> | ||
<mvc:mapping path="/user/retweet/{id}"/> | ||
|
||
<bean class="TwitMini.interceptor.AuthInterceptor"/> | ||
</mvc:interceptor> | ||
<mvc:interceptor> | ||
<mvc:mapping path="/index"/> | ||
<mvc:mapping path="/"/> | ||
<mvc:mapping path="/user/login"/> | ||
<mvc:mapping path="/user/register"/> | ||
<bean class="TwitMini.interceptor.HomeInterceptor"/> | ||
</mvc:interceptor> | ||
</mvc:interceptors> | ||
|
||
|
||
|
||
|
||
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> | ||
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> | ||
<property name="prefix" value="/WEB-INF/jsp/"/> | ||
<property name="suffix" value=".jsp"/> | ||
</bean> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.