您的位置:首页 > Web前端 > JavaScript

JSP页面用户目录文件路径合成

2009-05-08 01:28 411 查看
<%@page language="java" contentType ="text/html;charset=utf-8" pageEncoding = "utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
<html xmlns ="http://www.w3.org/1999/xhtml">
<head >
<title> Struts 2 File Upload </title>
</head>
<body>
<h2 align="center">
<font color="red">浏览文件</font>
</h2>
<div align="center">
<table align="center" bgcolor="#808000" border="1px" >
<tr bgcolor="yellow">
<th>序号</th>
<th>文件名</th>
<th>操作	</th>
</tr>
<s:set name="listIndex" value="0"/>
<s:iterator value="fileList">
<tr bgcolor="green">
<td class="nowrap" >
<s:property value="(#listIndex)+1"/>
<!-- 显示列号-->
</td>
<td class="nowrap">
<s:property value="fileList.get(#listIndex)" />
</td>
<td class="nowrap">
<s:url  id="url">

</s:url>

<%String username =(String)request.getSession().getAttribute("username");%>

<a href="<%=request.getContextPath()%>/<%=(String)request.getSession().getAttribute("username")%>/<s:property value="fileList.get(#listIndex)"/>" target="_blank">下载查看</a>
<s:url action="fileupload!DeleteFile" id="url">
<s:param name="operateFileName" value="fileList.get(#listIndex)" />
</s:url>
<a href="<s:property value=" mce_href="<s:property value="#url"></a>" onclick="return (confirm('确定刪除?'))">删除</a>
</td>
</tr>
<s:set name="listIndex" value="#listIndex+1" />
</s:iterator>
</table>
</div>
<div align="center">
<s:url id="url" action="fileupload!refresh" />
<a href="<s:property value=" mce_href="<s:property value="#url"></a>">刷新</a>
</div>
<div align="center">
<s:url id="url"  />
<a href="<%=request.getContextPath()%>/FileUpload.jsp">上传文档</a>
</div>
<div align="center">
<s:url id="url" />
<a href="<%=request.getContextPath()%>/Index.jsp">返回</a>
</div>
</body>
</html>


这个段代码主要是为了说明怎样在页面上拼合出一个文件的服务器路径。

在这个页面上,一个文件的服务器绝对路径由三部分组成。服务器根目录,以用户名命名的文件目录,由迭代器中的名字的文件。

request.getContextPath();//得到系统根目录

String usernaeme = (String)request.getSession.getAttribute("username");//得到用户名

fileList.get(#listIndex) //得到文件名

它们的拼凑方式很特别:

<a href="<%=request.getContextPath()%>/<%=(String)request.getSession().getAttribute("username")%>/<s:property value="fileList.get(#listIndex)"/>" target="_blank">下载查看</a>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐