struts2-登陆以及藏静态资源到/WEB-INF

2017-04-07  本文已影响0人  Maybrittnelson

登陆:
dao: criteria.add(Restrictions.eq("name", name));
service:
User u = dao.get(user.getName)
if(u==null)
抛出不存在用户名异常
if(!user.getPwd.eq(u.getPwd))
抛出不存在密码异常
return u;
interceptors:
1.自定拦截器LoginInterceptor extends MethodFilterInterceptor
2.return "toLogin";
action:
User u = service.get(user);
return "toindex"//重定向避免表单重复提交..
struts.xml:

  1. <interceptors>
    <interceptor name="loginInterceptor" class> </interceptor>
    < interceptor-stack name="myStack">
    <interceptor-ref name="loginInterceptor" >
    <param name="excludeMethods">login, regist</param>
    </interceptor-ref>
    <interceptor-ref name="defaultStack"></interceptor-ref>
    </interceptor-stack>
    </interceptors>
    <def-interceptor-ref name=""></def-interceptor-ref>
  2. <gloabl-result>
    <result name="toLogin"></result>
    </gloabl-result>
    3.<gloabl-exception-mappings>
    <exception-mapping result="error" class="java.lang.RunntimeException">
    </exception-mapping>
    </gloabl-exception-mappings>
    <action name="UserAction_*" method={1} class="...">
    <result name="toindex" type="redirectAction">page_index</result>
    <result name="error">/login.jsp</result>
    </action>
    4.隐藏静态资源至WEB-INF中: <action name="page_*">
    <result >/WEB-INF/page_{1}</result>
    </action>
    页面需从valueStack中接收exception.message:
    <s:property value="exception.message">
上一篇下一篇

猜你喜欢

热点阅读