请教各位大大,就是不同的用户登录呈现列表显示所有查询出的注册用户信息,项目中有增删改查,和多表联合查询五个功能,最高权限可以使用所有功能,但是一般权限就只能使用自己的多表联合查询出自己的个人信息这个功能。如果有相关代码案例,请发我一份,谢谢!

解决方案 »

  1.   

    先写一个拦截器类:public class AuthorityInterceptor extends AbstractInterceptor { public String intercept(ActionInvocation invocation) throws Exception { ActionContext ctx = invocation.getInvocationContext();
    Map session = ctx.getSession();
    User1 user = (User1) session.get("user");
    HttpServletRequest request = ServletActionContext.getRequest();
    String type= request.getParameter("type");
    int num = Integer.parseInt(type);
    System.out.println("页面上的值"+num);
    System.out.println("SQL中的值"+user.getType());
    if (user.getName() != null && user.getName().equals("zhangkun")&&user.getType().equals(num)) {

    return invocation.invoke();
    }
    else if (user.getName() != null && user.getName().equals("ma")&&user.getType().equals(num)) {

    return invocation.invoke();
    }
    ctx.put("tip", "對不起,你没有此权限!");
    return Action.LOGIN;
    }}然后在struts.xml中配置所需要拦截的类。<interceptors>
    <interceptor name="auth"
    class="com.sy.interceptor.AuthorityInterceptor">
    </interceptor>
    <interceptor-stack name="authStack">   
    <interceptor-ref name="auth"></interceptor-ref>
    <interceptor-ref name="defaultStack"></interceptor-ref>
    </interceptor-stack>
    </interceptors>
    <action name="companyfile" class="com.sy.action.files" method="Query1">
    <result name="success">/WEB-INF/jsp/Page1.jsp</result>
    <result name="login">/Error.jsp</result>
    <interceptor-ref name="authStack"></interceptor-ref>
    </action>
      

  2.   

    LZ,你是怎么做的,可以给我发一份参考参考吗? 邮箱[email protected] 谢谢
      

  3.   

    LZ,能给我发一份参考吗?[email protected]