今天看了一段代码,里面有这个登录权限检查:
public class AuthorityInterceptor implements MethodInterceptor
06.{
07. public Object invoke(MethodInvocation invocation) throws Throwable
08. {
09. HttpServletRequest request = null;
10. ActionMapping mapping = null;
11. Object[] args = invocation.getArguments();
12. for (int i = 0 ; i < args.length ; i++ )
13. {
14. if (args[i] instanceof HttpServletRequest) request = (HttpServletRequest)args[i];
15. if (args[i] instanceof ActionMapping) mapping = (ActionMapping)args[i];
16. }
17. Object admin = request.getSession().getAttribute("admin");
18. if ( admin != null && ((String)admin).equals("admin"))
19. {
20. return invocation.proceed();
21. }
22. else
23. {
24. request.setAttribute("msg" , "您还没有登录,请先登录");
25. return mapping.findForward("admin");
26. }
27. }
28.} 我想问一下在第17行request.getSession().getAttribute("admin")这一句,admin是什么时候设到Session里面去的?为什么这里可以直接拿来用啊?
public class AuthorityInterceptor implements MethodInterceptor
06.{
07. public Object invoke(MethodInvocation invocation) throws Throwable
08. {
09. HttpServletRequest request = null;
10. ActionMapping mapping = null;
11. Object[] args = invocation.getArguments();
12. for (int i = 0 ; i < args.length ; i++ )
13. {
14. if (args[i] instanceof HttpServletRequest) request = (HttpServletRequest)args[i];
15. if (args[i] instanceof ActionMapping) mapping = (ActionMapping)args[i];
16. }
17. Object admin = request.getSession().getAttribute("admin");
18. if ( admin != null && ((String)admin).equals("admin"))
19. {
20. return invocation.proceed();
21. }
22. else
23. {
24. request.setAttribute("msg" , "您还没有登录,请先登录");
25. return mapping.findForward("admin");
26. }
27. }
28.} 我想问一下在第17行request.getSession().getAttribute("admin")这一句,admin是什么时候设到Session里面去的?为什么这里可以直接拿来用啊?
解决方案 »
- 为什么 有 积分 ,可 还是 无法 下载 资源 ??????
- inframe间调用
- 这个jsp页什么错误?
- 如何将JSP变量的值赋给JavaScript的变量??急呀!!!在线等到00:00
- JSP+MS SQL+JAVABEAN问题
- 如何更改tomcat的主目录
- Cannot call sendError() after the response has been committ
- 怎么设置Access数据库的数据源
- 我想把数据库中的表限制在500行以内,该怎么做(Andrawu来看看)?
- 在JSP中使用JAVABEAN的包是怎样生成的?
- 如何实现定时查询数据库??
- 在java中将json对象传入memcached时遇到的问题
32.
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
33. <property name="beanNames">
34. <list>
35. <value>/processAddStudent</value>
36. <value>/listStudent</value>
37. <value>/delStudent</value>
38. <value>/processAddTest</value>
39. <value>/addQuestion</value>
40. <value>/delQuestion</value>
41. <value>/processAddQuestion</value>
42. </list>
43. </property>
44. <property name="interceptorNames">
45. <list>
46. <value>authorityInterceptor</value>
47. </list>
48. </property>
49. </bean>
50. <bean id="authorityInterceptor" class="org.yeeku.action.authority.AuthorityInterceptor"/> 请问第35行到第41行的<value>标签里面的内容是什么啊?这些类也是要用户自己去定义的么?谢谢
依照你发出来的看,通过<property name="beanNames"> (bean名字) 就是以下的:
<list>
35. <value>/processAddStudent</value>
36. <value>/listStudent</value>
37. <value>/delStudent</value>
38. <value>/processAddTest</value>
39. <value>/addQuestion</value>
40. <value>/delQuestion</value>
41. <value>/processAddQuestion</value>
42. </list> bean名字同list组里面value相同的名字使用aop功能这些类一般是需要自己去定义的,基本上都是设置在service层
大概意思是不是登录进来的用户想进行上面list里面的操作时,自己的AOP就会执行check工作,如果是admin用户,就放行,要是不是,就提示“权限不足”?