现手上有一项目。
里面有一日志下载功能,该功能目前还没有完善。
现在遇到的问题是。
当用户进入日志下载页面时,能看见所有的用户的日志。
而我需要做的是只看见本人,本用户的日志,其他用户的看不见。
本来很简单,直接在后台写个查询语句。
但是这个项目的整体架构啊都跟本人没关系。
日志下载列表里面的值都通过Fro循环直接从文件夹遍历出来的。
所以现在要在JSP页面添加相关判断,来实现,用户只能查看自己的日志功能。
请大家帮帮忙。谢了。
里面有一日志下载功能,该功能目前还没有完善。
现在遇到的问题是。
当用户进入日志下载页面时,能看见所有的用户的日志。
而我需要做的是只看见本人,本用户的日志,其他用户的看不见。
本来很简单,直接在后台写个查询语句。
但是这个项目的整体架构啊都跟本人没关系。
日志下载列表里面的值都通过Fro循环直接从文件夹遍历出来的。
所以现在要在JSP页面添加相关判断,来实现,用户只能查看自己的日志功能。
请大家帮帮忙。谢了。
<%
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("没有相关记录!");
}
}
%>
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("没有相关记录!");
}
}
%>
这个mtUserId是什么?你如果想找到mtUserId对应的userName属性的话,这里面应该放你从session中取出来的userId才是啊?你这个mtUserId明明就是你for循环里面的啊。这样判断难道有意义吗?
就可以改为String userName = MemoryData.getUserName(userId);
括号里面的userId是你从session中取出来的用户Id
是代表ID 但是有什么区别吗?
mtUserId它都代表ID了,我在JSP页面里面打印mtUserId它把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);试试
如果你直接String userName = MemoryData.getUserName(mtUserId);
然后if(userName!=null)这样判断的话是没有意义的!这样userName……
[/Quote]
没用 改成userid 还是没用。不知道为什么,郁闷。
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的!)
<%@ 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>这个页面完整的。
没txt的 是直接从文件夹里面读取出来的。 遍历出来的 直接读的文件夹的路径。
你的item[0]什么意思?代表娶到的是id???我看不是吧 这是取得什么?这代表取了这个数组对象的某一个元素,他包含的是?
将它if(mtUserId !=null)改为if(mtUserId ==userId)试试
../mtLogFile/ 就在这个文件的路径啊 然后里面放的是备份的日志