现手上有一项目。
里面有一日志下载功能,该功能目前还没有完善。
现在遇到的问题是。
当用户进入日志下载页面时,能看见所有的用户的日志。
而我需要做的是只看见本人,本用户的日志,其他用户的看不见。
本来很简单,直接在后台写个查询语句。
但是这个项目的整体架构啊都跟本人没关系。
日志下载列表里面的值都通过Fro循环直接从文件夹遍历出来的。
所以现在要在JSP页面添加相关判断,来实现,用户只能查看自己的日志功能。
请大家帮帮忙。谢了。

解决方案 »

  1.   

    那你再写个条件判断 将你本人的日志过滤出来呗!你登陆的时候应该可以取到你的用户信息吧。根据你的用户信息与你通过Fro循环直接从文件夹遍历出来的数据结果匹配过滤出自己的日志信息!!!
      

  2.   


    <%
    Long userId = (Long)session.getAttribute("userId");
     if(userId == null) {
    %><script>top.window.location.href='../loginError.htm'</script><%
    return;
    }%></head>
    <body><%
    String filePath = application.getRealPath("\\mtLogFile\\");
    File filedir = new File(filePath);
     for(File file : filedir.listFiles()) {
    String fileName = file.getName();
    String[] items = fileName.split("_");
    if(items.length != 2) continue;
    long mtUserId = Long.parseLong(items[0]);
    String userName = MemoryData.getUserName(mtUserId);
    //out.print(userId);
    out.print(mtUserId);

    if(userName!=null){

    %>
    <a href="<%="../mtLogFile/"+fileName%>"><%=userName + " " + items[1]%></a>
    <a href="mtLog_rate.jsp?fileName=<%=fileName.substring(0, fileName.length()-3) + ".txt"%>&keepThis=true&TB_iframe=true&height=250&width=400" title="调整文件" class="thickbox">调整文件</a>
    <br/>
    <%
        }else{

    out.print("没有相关记录!");

    }
    }
    %>
      

  3.   

    你做了判断了吗?我只看到你从session中取出了userId,但是没看到你用到userId啊!
      

  4.   

    物品判断啦  前面不是有一句话把ID赋给USERNAME了啊  所以我判断的NAME啊!
      

  5.   

    <%
    Long userId = (Long)session.getAttribute("userId");
     if(userId == null) {
    %><script>top.window.location.href='../loginError.htm'</script><%
    return;
    }%></head>
    <body><%
    String filePath = application.getRealPath("\\mtLogFile\\");
    File filedir = new File(filePath);
     for(File file : filedir.listFiles()) {
    String fileName = file.getName();
    String[] items = fileName.split("_");
    if(items.length != 2) continue;
    long mtUserId = Long.parseLong(items[0]);
    String userName = MemoryData.getUserName(mtUserId);
    //out.print(userId);
    out.print(mtUserId);

    if(userName!=null){

    %>
    <a href="<%="../mtLogFile/"+fileName%>"><%=userName + " " + items[1]%></a>
    <a href="mtLog_rate.jsp?fileName=<%=fileName.substring(0, fileName.length()-3) + ".txt"%>&keepThis=true&TB_iframe=true&height=250&width=400" title="调整文件" class="thickbox">调整文件</a>
    <br/>
    <%
        }else{

    out.print("没有相关记录!");

    }
    }
    %>
      

  6.   

    String userName = MemoryData.getUserName(mtUserId);
    这个mtUserId是什么?你如果想找到mtUserId对应的userName属性的话,这里面应该放你从session中取出来的userId才是啊?你这个mtUserId明明就是你for循环里面的啊。这样判断难道有意义吗?
      

  7.   

    只是想问下你的那个mtUserId是什么属性,如果是表示userId的话
    就可以改为String userName = MemoryData.getUserName(userId);
    括号里面的userId是你从session中取出来的用户Id
      

  8.   


    是代表ID  但是有什么区别吗?
    mtUserId它都代表ID了,我在JSP页面里面打印mtUserId它把ID的值也取出来了。
      

  9.   

    是代表ID  但是有什么区别吗?
    mtUserId它都代表ID了,我在JSP页面……
    [/Quote]
    mtUserId是你从文件夹遍历出来的,所以就表示文件夹中所有的mtUserId,
    如果你直接String userName = MemoryData.getUserName(mtUserId);
    然后if(userName!=null)这样判断的话是没有意义的!这样userName始终不为null。
    如果你通过从session中获取当前用户的userId的话,就只会判断是当前用户userName才不为null
    所以将String userName = MemoryData.getUserName(mtUserId);
    改为:String userName = MemoryData.getUserName(userId);试试
      

  10.   

    mtUserId是你从文件夹遍历出来的,所以就表示文件夹中所有的mtUserId,
    如果你直接String userName = MemoryData.getUserName(mtUserId);
    然后if(userName!=null)这样判断的话是没有意义的!这样userName……
    [/Quote]
    没用 改成userid 还是没用。不知道为什么,郁闷。
      

  11.   

    天呐!你们真会聊啊。文件格式应该就像这样:
    id=1 name=xxx conten=wddsdsd;
    id=2 name=ddd conten=dddddss;
    id=3 name=sss conten=qqwqwqw;首先解析这个文件流split(";")
    并把它用数组保存
    再遍历数组用map保存数组的每一个元素,Map<Interger,Object> 
    map.put(XX用户id,XX用户全部信息);
    这样才方便比较文件里面的用户id和登录的用户的id。
    用户id直接从session获取,文件里面的用户id从map里面拿(遍历map,如果map的id==session的id,返回这个id对应的结果集此时应该会OK的!)
      

  12.   

    结果是什么?还是输出所有的日志吗?建议你先在页面输出你从session中取到的userId,看看是否取到了!然后在for中输出String userName = MemoryData.getUserName(userId);中的userName。看看取出了多少次
      

  13.   

    session中ID取到了,但是他还是输出全部的日志啊。SESSION中肯定取到了 如果取不到的话,他怎么输出日志列表,那样的话会报错的。
      

  14.   


    <%@ page contentType="text/html; charset=gbk"%><%@page import="java.io.File"%>
    <%@page import="smartmt.init.MemoryData"%>
    <%@page import="smartmt.model.User"%>
    <%@page import="smartmt.db.UserDao"%>
    <%@page import="smartmt.db.DataSourceFactory"%>
    <%@page import="javax.sql.DataSource"%><html>
    <%@ taglib uri="http://displaytag.sf.net" prefix="display" %>
    <head>
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <style type="text/css" media="all">
    @import url("../css/displayTag/maven-base.css");
           @import url("../css/displayTag/maven-theme.css");
           @import url("../css/displayTag/site.css");
           @import url("../css/displayTag/screen.css");
    </style>
    <link type="text/css" href="../css/sunny/jquery-ui-1.8.1.custom.css" rel="stylesheet" />
    <link type="text/css" href="../css/sunny/demos.css" rel="stylesheet" />
    <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="../js/jquery-ui-1.8.1.custom.min.js"></script>
    <script type="text/javascript">
    $(function() {
    $('#dateStart').datepicker();
    $('#dateEnd').datepicker();
    $("#tabs").tabs({
    ajaxOptions: {
    error: function(xhr, status, index, anchor) {
    $(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
    }
    }
    });
    });
    </script>
    <%
    Long userId = (Long)session.getAttribute("userId");
     if(userId == null) {
    %><script>top.window.location.href='../loginError.htm'</script><%
    return;
    }%></head>
    <body><%
    String filePath = application.getRealPath("\\mtLogFile\\");
    File filedir = new File(filePath);
     for(File file : filedir.listFiles()) {
    String fileName = file.getName();
    String[] items = fileName.split("_");
    if(items.length != 2) continue;
    long mtUserId = Long.parseLong(items[0]);
    String userName = MemoryData.getUserName(userId);
    //out.print(userId);
    out.print(mtUserId);

    if(userName!=null){

    %>
    <a href="<%="../mtLogFile/"+fileName%>"><%=userName + " " + items[1]%></a>
    <a href="mtLog_rate.jsp?fileName=<%=fileName.substring(0, fileName.length()-3) + ".txt"%>&keepThis=true&TB_iframe=true&height=250&width=400" title="调整文件" class="thickbox">调整文件</a>
    <br/>
    <%
        }else{

    out.print("没有相关记录!");

    }
    }
    %>
    </body>
    </html>这个页面完整的。
      

  15.   

    我要看你的日志文件,就是txt的那个···
      

  16.   


    没txt的  是直接从文件夹里面读取出来的。 遍历出来的 直接读的文件夹的路径。
      

  17.   

    long mtUserId = Long.parseLong(items[0]);
    你的item[0]什么意思?代表娶到的是id???我看不是吧 这是取得什么?这代表取了这个数组对象的某一个元素,他包含的是?
      

  18.   

    lz,你把你的判断改下
    将它if(mtUserId !=null)改为if(mtUserId ==userId)试试
      

  19.   

    文件夹总该有东西吧?哥。把东西copy来看看
      

  20.   


    ../mtLogFile/ 就在这个文件的路径啊 然后里面放的是备份的日志