zoukankan      html  css  js  c++  java
  • struts配置

    配置:

    拦截登陆

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>

    <constant name="struts.multipart.maxSize" value="104857600"/>
    <package name="interceptor" namespace="/" extends="struts-default">

    <!-- 配置拦截器 -->
    <interceptors>
    <interceptor name="loginInterceptor" class="com.oak.interceptor.LoginIntercrptor"></interceptor>
    <!-- 配置拦截器栈 -->
    <interceptor-stack name="mysql">
    <!-- 系统拦截器栈,,name值是固定的 -->
    <interceptor-ref name="defaultStack"></interceptor-ref>
    <interceptor-ref name="loginInterceptor">


    <param name="excludeMethods">toLogin,login</param>
    </interceptor-ref>
    </interceptor-stack>
    </interceptors>

    <!-- 设置全局拦截器 -->
    <default-interceptor-ref name="mysql"></default-interceptor-ref>
    <!-- 公共跳转页
    global-results一般和全局拦截器(比如方法拦截器)
    搭配使用 -->
    <global-results>
    <result name="relogin">
    /login.jsp
    </result>
    </global-results>


    </package>
    <include file="../../cfg/ajax-struts.xml"></include>
    <include file="../../cfg/big-struts.xml"></include>
    <include file="../../cfg/bill-struts.xml"></include>
    <include file="../../cfg/goods-struts.xml"></include>
    <include file="../../cfg/small-struts.xml"></include>
    <include file="../../cfg/sup-struts.xml"></include>
    <include file="../../cfg/user-struts.xml"></include>
    </struts>

     普通

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>

    <package name="goods" namespace="/" extends="interceptor">

    <action name="goodslist" class="goodsAction" method="goodspagelist">
    <result name="success">
    /goods.jsp
    </result>
    </action>
    <!-- 商品模糊查询 -->
    <action name="goodlike" class="goodsAction" method="goodlike">
    <result name="success">
    /goods.jsp
    </result>
    </action>
    <action name="goodsadd" class="goodsAction" method="goodsadd">
    <result name="success" type="redirectAction">
    goodslist
    </result>
    </action>
    <action name="goodstoupdate" class="goodsAction" method="goodstoupdate">
    <result name="success">
    /goodstoupdate.jsp
    </result>
    </action>
    <action name="goodsupdate" class="goodsAction" method="goodsupdate">
    <result name="success" type="redirectAction">
    goodslist
    </result>
    </action>
    <action name="goodsdelete" class="goodsAction" method="goodsdelete">
    <result name="success" type="redirectAction">
    goodslist
    </result>
    </action>
    </package>
    </struts>

    拦截登陆

    public class LoginIntercrptor extends MethodFilterInterceptor{

    @Override
    protected String doIntercept(ActionInvocation ai) throws Exception {
    // TODO Auto-generated method stub
    ActionContext actionContext = ActionContext.getContext();
    Map<String, Object> session = actionContext.getSession();
    User s = (User) session.get("u");
    if (s==null) {
    return "relogin";
    } else {
    return ai.invoke();
    }

    }

    }

    action


    public String login(){
    System.out.println(123);
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    session.setAttribute("user", user.getUsername());
    System.out.println("user"+user);
    //绑定session
    ActionContext ac = ActionContext.getContext();
    Map<String, Object> session1 = ac.getSession();

    u = userService.login(
    user.getUsername(),
    user.getPassword());
    System.out.println("u"+u);
    if(u.getUsername() != null){
    session1.put("u", user);
    return SUCCESS;
    }else {
    return ERROR;
    }

    }

  • 相关阅读:
    tensorflow几个常见错误
    15、TDM模型
    算法97:成绩排名---动态规划
    推荐阅读论文
    Reservoir Sampling 蓄水池采样算法
    14、RALM: 实时 look-alike 算法在推荐系统中的应用
    NLP传统基础(3)---潜在语义分析LSA主题模型---SVD得到降维矩阵
    【SqlServer】SqlServer中的计算列
    【SQL】数据库中的五种约束
    【.NET】SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM之间
  • 原文地址:https://www.cnblogs.com/love1/p/7976832.html
Copyright © 2011-2022 走看看