jsp读取指定目录下的文件列表
有两级下拉菜单 第一级菜单已经实现 显示指定目录下的文件夹 二级菜单要求显示一级菜单选中的文件夹下的文件 不知道如何实现
javascript能够获取选中的文件夹名称 但是不知道二级菜单如何获取路径
代码如下 请指教<%@ page contentType="text/html" %>
<%@ page pageEncoding="GB2312" %>
<%@ page import="java.io.*" %>
<%! String dataPath;%>
<html>
<head>
<title>数据导入</title>
<script language="JavaScript">
<!--
function getDataPath()
{
var elefolLi=document.getElementById("folderList");
var eledataPath=elefolLi.options[elefolLi.selectedIndex].text;
var jsdataPath=eledataPath.toString();
//var jsdataPath.insertForm.submit();
alert(jsdataPath); //显示获取结果
}//-->
</script>
</head>
<body>
<form name="insertForm" method="post" action="testFileList.jsp">
<input type="hidden" id="jsdataPath" value="">
</form>
<form method="POST" action="runimport.jsp">
<p align="center" >
<table>
<tr>
<td>请选择数据类型:</td>
<td><input type=radio name=dataType value="temperature" checked>温度
<input type=radio name=dataType value="rain" >
降水
<input type=radio name=dataType value="press" >气压
</td>
</tr>
<tr>
<td>请选择目录:</td>
<td>
<select id="folderList" name='selectSS' size="1" onChange="getDataPath()">
<%
String folderPath="F:/JSP通用范例开发金典";
File folderList=new File(folderPath);
File list[]=folderList.listFiles();
for(int i=0;i<list.length;i++)
if(list[i].isDirectory())
{
out.print("<option>"+list[i].toString()+"<BR>");
}
%>
</select>
</td>
</tr>
<tr>
<td>请选择数据:</td>
<td>
<select id="siteData" size="1" onChange="">
<%
String dataPath="/";
File dataList=new File(dataPath);
File sublist[]=dataList.listFiles();
out.print("<option>选择数据<BR>");
for(int i=0;i<sublist.length;i++)
{
out.print("<option>"+sublist[i].toString()+"<BR>");
}
%>
</select>
</td>
</tr>
<tr>
<td>请选择插值方法:</td>
<td>
<select name="interpolationMethod" size="1">
<option value="OrdinaryKriging">普通克吕金
<option value="UniversalKriging">泛克吕金
<option value="CoKriging">协克吕金
</select>
</tr>
<tr>
<td>请选择等值线间距:</td>
<td>
<select name="contourInterval" size="1" >
<option>1
<option>2
<option>3
<option>5
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="确定" name="submit">
<input type="reset" value="重新选择" name="reset">
<input type="button" value="退出" name="close">
</td>
</tr>
</table>
</form>
<%
%>
</body>
</html>
有两级下拉菜单 第一级菜单已经实现 显示指定目录下的文件夹 二级菜单要求显示一级菜单选中的文件夹下的文件 不知道如何实现
javascript能够获取选中的文件夹名称 但是不知道二级菜单如何获取路径
代码如下 请指教<%@ page contentType="text/html" %>
<%@ page pageEncoding="GB2312" %>
<%@ page import="java.io.*" %>
<%! String dataPath;%>
<html>
<head>
<title>数据导入</title>
<script language="JavaScript">
<!--
function getDataPath()
{
var elefolLi=document.getElementById("folderList");
var eledataPath=elefolLi.options[elefolLi.selectedIndex].text;
var jsdataPath=eledataPath.toString();
//var jsdataPath.insertForm.submit();
alert(jsdataPath); //显示获取结果
}//-->
</script>
</head>
<body>
<form name="insertForm" method="post" action="testFileList.jsp">
<input type="hidden" id="jsdataPath" value="">
</form>
<form method="POST" action="runimport.jsp">
<p align="center" >
<table>
<tr>
<td>请选择数据类型:</td>
<td><input type=radio name=dataType value="temperature" checked>温度
<input type=radio name=dataType value="rain" >
降水
<input type=radio name=dataType value="press" >气压
</td>
</tr>
<tr>
<td>请选择目录:</td>
<td>
<select id="folderList" name='selectSS' size="1" onChange="getDataPath()">
<%
String folderPath="F:/JSP通用范例开发金典";
File folderList=new File(folderPath);
File list[]=folderList.listFiles();
for(int i=0;i<list.length;i++)
if(list[i].isDirectory())
{
out.print("<option>"+list[i].toString()+"<BR>");
}
%>
</select>
</td>
</tr>
<tr>
<td>请选择数据:</td>
<td>
<select id="siteData" size="1" onChange="">
<%
String dataPath="/";
File dataList=new File(dataPath);
File sublist[]=dataList.listFiles();
out.print("<option>选择数据<BR>");
for(int i=0;i<sublist.length;i++)
{
out.print("<option>"+sublist[i].toString()+"<BR>");
}
%>
</select>
</td>
</tr>
<tr>
<td>请选择插值方法:</td>
<td>
<select name="interpolationMethod" size="1">
<option value="OrdinaryKriging">普通克吕金
<option value="UniversalKriging">泛克吕金
<option value="CoKriging">协克吕金
</select>
</tr>
<tr>
<td>请选择等值线间距:</td>
<td>
<select name="contourInterval" size="1" >
<option>1
<option>2
<option>3
<option>5
</select>
</td>
</tr>
<tr>
<td>
<input type="submit" value="确定" name="submit">
<input type="reset" value="重新选择" name="reset">
<input type="button" value="退出" name="close">
</td>
</tr>
</table>
</form>
<%
%>
</body>
</html>
解决方案 »
- 大家在写OA时犯过什么致命错误?进来讨论一下 散50分!
- java在处理clob大字段时,报ORA-01006: 赋值变量不存在?
- POI上传EXCEL问题
- struts2上传文件过大 返回input页无错误提示 且如下input页面的title变为null
- 一串字符,前后的字符都是固定的,怎么求得中间的变化的字符串?
- 如何把错误信息显示在页面的顶端(指定位置)? 其它问题若干~
- Dev2Dev TechDays2008邀您加入Java2SOA技术拓展新革命
- request获得的Cookie为什么只有四个呢?
- 急:一个初学者的问题? 给分
- 请问:哪些服务器是Web服务器,哪些服务器是应用服务器?列举一点例子吧。谢谢!
- 怎样在jsp页面上画一棵树 不是树形菜单 就是把一个树形结点画出来
- 谁有Java 虚拟机的详细介绍说明啊!
当第一个下拉列表的事件触发的时候,往后台发送一个申请,更新第二个下拉列表的内容。
大体上是,通过JS往后台发送一个Request(具体是什么Request我记不得了),然后后台返回一个字符串,然后解析。
大概是这样,你看看专业的书籍吧。
简简单单的AJAX不难的。