那就不用XML的方式,换一种方式。
在同一文件夹下保存
-------------upload.htm-----主窗口--------<SCRIPT LANGUAGE="JavaScript">
<!--
function NewWindow(){
var args;
var Height = 60;
var Width = 450;
strStyle = "help:no;"+
"minimize:no;" +
"maximize:no;" + 
"border:thick;" +
"statusbar:no;" +
"dialogWidth:"+Width+"px;" +
"scroll:no;" +
"dialogHeight:"+Height+"px;" +
"center:yes;" +
"status:no;" +
"edge: raised";
args = window.showModalDialog("attachmain.htm","",strStyle);
if(typeof(args)=="object"){
var oOption = document.createElement("OPTION");
document.all.textSelect.options.add(oOption);
oOption.value = args[1];
oOption.innerText = args[0];
document.all.textSelect.selectedIndex = oOption.index;
}
}
//-->
</SCRIPT>
…………
主窗口:
…………
<input class="bbox"  type="button" value="读号码" ONCLICK="NewWindow()" >
<select name="textSelect" size="8"  class=self style="WIDTH:93%" height="20">
    将弹出窗口页面执行的结果掉回显示在这里</select>------------------------attachmain.htm----增加附件的框架------------------
<html>
<head>
<title>附件管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<frameset rows="*,0" frameborder="NO" border="0" framespacing="0"> 
  <frame name="topFrame" scrolling="NO" noresize src="attachment.htm">
  <frame name="mainFrame" src="#">
</frameset>
<noframes> 
<body bgcolor="#FFFFFF" text="#000000">
</body>
</noframes> 
</html>
------------------------Attachment.htm----子框架-----------------------<html>
<head>
<title>上传附件</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK rel="stylesheet" type="text/css" href="../includes/CssLib/style.css">
<script language="javascript" src="../includes/Jslib/check.js"></script>
<script language="javascript">
function btnCancel_onclick(){
parent.close();
}
function btnAdd_onclick(){

if (document.form1.file1.value.replace(/^\s*|\s*$/gi,"")=="")
{
myAlertWindow(1,"请选择一个文件");
document.form1.file1.select();
return false;
}
var strMatchString = parent.window.dialogArguments;
document.form1.action = "uploadpost.htm";
document.form1.submit();
}
</script><!-- 按钮 -->
<style>
.button {
width:74px;
padding-top:3px;
background-position:top left right bottom;
color:black;
font-size:12.6px;
text-align:center
}

.textbox { 
BORDER-BOTTOM:1px ; 
BORDER-LEFT:1px ;  
BORDER-RIGHT:1px solid; 
BORDER-TOP:1px solid;

}
</style>

</head>
<body leftmargin="10" topmargin="3" marginwidth="0" marginheight="0">
<form name="form1" enctype="multipart/form-data" method="post">
<table  border="0" cellpadding="1" cellspacing="1" >
  <tr> 
    <td width="20%">添加附件:</td>
  </tr>
  <tr> 
    <td>
        <input name="file1" type="file" id="file1" size="47" class="textbox">
    </td>
  </tr>
  <tr> 
    <td>
<table><tr>
<td>
<INPUT TYPE="button" value="ok" onclick="btnAdd_onclick()">
</td>
<td>
<INPUT TYPE="button" value="cancel" onclick="btnCancel_onclick()">
</td>
</tr></table>
    </td>
  </tr>
</table>
</form>
</body>
</html>------------------------uploadpost.htm--实际传文件的文件--------(将此页变成动态页)
<script language=javascript>
var returnArray = new Array();
returnArray[1] = 111;
returnArray[0] = 222;
parent.window.returnValue=returnArray;
parent.window.close();
</script>

解决方案 »

  1.   

    谢谢 你们friendlyFour(web开发四人组) 
    我把你们的全部拷贝过来了 但是刚决还是不能实现我那的功能这样吧 我把 我的所有需要用的文件代码贴出来给你门 你们帮我在这文件的基础上修改 好了再贴出来好吗???谢谢了 不好意思麻烦你们了
    主窗口代码:
    ——————————————————duanxinfasong.html————————————————
    <html>
    <head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <link href='../../css/css.css' rel='stylesheet' type='text/css'>
    <script language="JavaScript">
    function NewWindow()
    {
    window.open("http://car.wap888.cn/jspwen/fuwu/ziyouduanxin/tijao.html","","height=200,width=350,left=10,top=10,status=no,location=no,toolbar=no, directories=no,menubar=no");
    }function addOption(){   var sjh=document.form1.T1.value;
       if(isNaN(sjh))
      {
      alert("你输入的手机号码不是数字!");
      return(false);
      }
    if(sjh=="")
      {
          alert("不能输入空值!");
      return(false);
    }
      if(sjh.indexOf("13")==-1)
      {
        alert("你输入的不是13开头的手机号!");
    return(false);
      }
      if(sjh.length!=11)
      {
        alert("你输入的手机号不是11位!");
    return(false);
      }
    else {    addValue=document.form1.T1.value;
    var option=document.createElement("OPTION");
    option.value=addValue;
    option.text=addValue;
    form1.textSelect.add(option)
    }
    }
    function doSubmit(){
        var phaseString = "";
        var optionsArray = document.all("textSelect").children;
        var selectString="";
        for (var i = 0 ; i < optionsArray.length ; i++){
            selectString = selectString + phaseString + optionsArray[i].value;
        }
        document.all("selectValue").value=selectString;
    }
    function clear_text1()//清空
    {
    var textSelect;
     while(Number(form1.textSelect.options.length) > 0) 
     {
    form1.textSelect.options.remove(Number(form1.textSelect.options.length-1));// 这样试试
    }
    }
    function clear_text2()//删除
    {
    try{
    for(var i=0;i<form1.textSelect.options.length;i++)
    {
    if(form1.textSelect.options[i].selected)
    {
      form1.textSelect.remove(i);
      i=i-1;
    }
    }

    }
    catch(e){}
    }
    </script>
    <script>
    function chklen()
    {
    len=0;
    for(var begin = 0; begin < document.form1.S2.value.length; begin++)
    {

    len+=1;
    }
    len=70-len;
    if(len>=0)
    {
    tno.innerText = len;
            tno.style.color = "ff0000";
    }
    else
    {
    tno.innerText = ",不对,应该删去" + -(len);
    tno.style.color = "ff0000"; }
    }
    function checklen()
    {
    if(len<0)
    {
    alert("\内容超长" + -(len) + "个字,请修改 !!")
    return(false);
    }
    return(true);
    }
    document.onkeyup=chklen;
    </script>
    <script language="javascript">
    function check(){
    var t1=document.form1.textSelect.value;var d6=document.form1.S2.value;
    if( t1=="" && d6=="")
    {
    alert("不能空值发送数据请输入数据后再发!");
    return false;
    }
      
    } </script>
    </head>
    <form method="POST" action="dxfspost.jsp" name="form1"  ><table border="0" cellpadding="0" cellspacing="0" width="629" height="397" bgcolor="#999999" cellspacing="1">
    <tr>
    <td valign="top" height="53" width="90" bgcolor="#FDFAFB">

    <p align="center">
    <input type=image src="../../../images/shezhi/changjia.jpg" name=submit width="32" height="32" onclick="check();doSubmit();"><input type="hidden" value="" name="selectValue"><br>
    立即发送</td>
    <td valign="top" height="53" width="69" bgcolor="#FDFAFB">
        <p align="center">
    <input type=image src="../../../images/fuwu/freesms.jpg" width="32" height="32" name=reset><br>
    重新输入</td>
    <td valign="top" height="53" width="72" bgcolor="#FDFAFB">

    <p align="center">
    <img border="0" src="../../../images/shezhi/system.jpg" width="33" height="35"><br>
    关闭</td>
    <td valign="top" height="53" width="319" bgcolor="#FDFAFB">

     </td>
    </tr>
    <tr>
    <td valign="top" height="31" width="629" colspan="5" bgcolor="#FDFAFB">

    <p>&nbsp;&nbsp; 号码:<input class="bbox"  type="text" name="T1" size="20" autocomplete=off>&nbsp;<input class="bbox"  type="button" onClick="javascript:addOption();" value="增加">&nbsp;
    <input class="bbox"  type="button" value="读号码" ONCLICK="NewWindow()" >&nbsp;
    <input class="bbox"  type="button" value="删除" name="B3" onClick="javascript:clear_text2();">&nbsp;
    <input class="bbox"  type="reset" value="清空" name="B4" onClick="javascript:clear_text1();"></p>
    </td>
    </tr>
    <tr>
      <td valign="top" width="629" colspan="5" bgcolor="#FDFAFB">
      <p align="center">
    <select name="textSelect" size="8"  class=self style="WIDTH:93%" height="20">
        </select>

      </td>
    </tr>
    <tr>
    <td valign="top" width="629" colspan="5" height="12" bgcolor="#FDFAFB">

    <p align="center"><b><font size="3">发送内容</font></b>

    </tr>
    <tr>
    <td valign="top" width="629" colspan="5" height="137" bgcolor="#FDFAFB"> <p align="center">
    <textarea class=self rows="10" name="S2" cols="112" maxlength=""></textarea>
    </td>
    </tr>
    <tr>
    <td  bgcolor="#FDFAFB"  width="629" colspan="5">
    <p align="center">注意:    
    注意:您的短信内容还可输入<span id="tno">70</span>个字。
    </td> </tr>
    <tr><td bgcolor="#FDFAFB"  height=100 colspan=5></td></tr>
    </table>
    </form>
    </html>
    主窗口中 读号码 按纽 弹出的窗口代码:——————————————tijao.html——————————————————
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta NAME="Generator" CONTENT="EditPlus">
    <meta NAME="Author" CONTENT="">
    <meta NAME="Keywords" CONTENT="">
    <meta NAME="Description" CONTENT="">
    </head>
    <body bgcolor="#FDFAFB">
    <br>
    <br>
    <br>
    <center>
    <form name=form1 action="uploadpost.jsp"  method="POST" enctype="multipart/form-data"><table border="0" bgcolor="#F4F8FE" cellpadding="0" cellspacing="1" >
    <tr bgColor=#ffffff>
    <td>文件名</td>
    <td><input type="file" name="file" ></td></tr>
    <tr>
    <td><input type="submit" value="确定" </td></tr>
    <tr>
    <td colspan="2" height="20"><div align="center">请按规定上传文本(.txt)文件</div></td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>
      

  2.   

    因为内容长了点 所以还有一段:
    获得上传文件里面的内容程序:
    ——————————————————action="uploadpost.jsp"————————————
    <%@ page contentType="text/html; charset=gb2312" %> 
    <%@ page language="java" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*"%> 
    <%@ page import="java.util.*"%> 
    <%@ page import="javax.servlet.*"%> 
    <%@ page import="javax.servlet.http.*"%> 
    <html> 
    <head> 
    <title> 
    万科 
    </title> 
    </head> 
    <body bgcolor="#ffffff"> 
    <center> 
    <% 
    int n=0;
    int MAX_SIZE = 102400 * 102400;//定义上载文件的最大字节 
    String rootPath; // 创建根路径的保存变量
    DataInputStream in = null; //声明文件读入类
    FileOutputStream fileOut = null; 
    String remoteAddr = request.getRemoteAddr();//取得客户端的网络地址IP 
    out.print(remoteAddr); 
    out.print("<br>");
    String serverName = request.getServerName(); //获得服务器的名字 
    %>你访问的网站是:<%out.print(serverName); 
    out.print("<br>");
    //取得jsp文件相对与根地址的地址 
    out.print(request.getServletPath()); 
    out.print("<br>");
    String realPath = request.getRealPath(serverName); //取得互联网程序的绝对地址
    /out.println(realPath); 
    out.print("<br>");
    realPath = realPath.substring(0,realPath.lastIndexOf("\\")); 
    out.print(realPath); 
    rootPath = realPath + "\\upload\\"; //创建文件的保存目录upload
    %>传到服务器上的路径是:<% out.println(rootPath); String contentType = request.getContentType(); //取得客户端上传的数据类型 
    out.println("<p>客户端上传的数据类型 = " + contentType + "</p>"); 
    try{ 
    /*if(contentType != null && contentType.indexOf("multipart/form-data") >= 0)
    { */
    //读入上传的数据 
    in = new DataInputStream(request.getInputStream()); 
    int formDataLength=request.getContentLength(); 
    if(formDataLength > MAX_SIZE){ 
    out.print("<P>上传的文件字节数不可以超过"+ MAX_SIZE + "</p>"); 
    return; 

    //保存上传文件的数据 
    byte dataBytes[] = new byte[formDataLength];//放在一个字符数组里 
    int byteRead = 0; 
    int totalBytesRead = 0; 
    //上传的数据保存在byte数组 
    while(totalBytesRead < formDataLength)

    byteRead = in.read(dataBytes,totalBytesRead,formDataLength); 
    totalBytesRead += byteRead; 

    //根据byte数组创建字符串 
    String file = new String(dataBytes); 
    //out.println(file); 
    //取得上传的数据的文件名 
    String saveFile = file.substring(file.indexOf("filename=\"") + 10); 
    saveFile = saveFile.substring(0,saveFile.indexOf("\n")); 
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+1,saveFile.indexOf("\"")); 
    int lastIndex = contentType.lastIndexOf("="); 
    //取得数据的分隔字符串 
    String boundary = contentType.substring(lastIndex + 1,contentType.length()); 
    //创建保存路径的文件名 
    String fileName = rootPath + saveFile; 
    //out.print(fileName); 
    int pos; 
    pos = file.indexOf("filename=\""); 
    pos = file.indexOf("\n",pos) + 1; 
    pos = file.indexOf("\n",pos) + 1; 
    pos = file.indexOf("\n",pos) + 1; 
    int boundaryLocation = file.indexOf(boundary,pos) - 4; 
    //out.println(boundaryLocation); 
    //取得文件数据的开始的位置 
    int startPos =((file.substring(0,pos)).getBytes()).length; 
    //out.println(startPos); 
    //取得文件数据的结束的位置 
    int endPos = ((file.substring(0,boundaryLocation)).getBytes()).length; 
    //out.println(endPos); 
    //检查上载文件是否存在 
    File checkFile = new File(fileName); 
    if(saveFile.indexOf(".txt")<0)
    {
    out.print("<p>你上传的文件不是文本文件!</p>");
    }
    else {
    if(checkFile.exists())

    out.println("<p>" + saveFile + "文件已经存在.</p>"); 

    //检查上载文件的目录是否存在 
    File fileDir = new File(rootPath); 
    if(!fileDir.exists())

    fileDir.mkdirs(); 

    //创建文件的写出类 
    fileOut = new FileOutputStream(fileName); 
    //保存文件的数据 
    fileOut.write(dataBytes,startPos,(endPos - startPos)); 
    fileOut.close(); 
    out.println("<P>" + saveFile + "文件成功上载.</p>"); 
    /*}else{ 
    String content = request.getContentType(); 
    out.println
    ("<p>上传的数据类型不是是multipart/form-data</p>"); 
    } */
    %>上传的文件内容是:<br><%
     FileReader fr=new FileReader(rootPath +saveFile);
    //建立BufferedReader变量, 并设定由br变量引用
       BufferedReader br=new BufferedReader(fr);
    //自文件读取一行字串
       String Line=br.readLine();
        while(Line!=null)
      {
     out.print(Line+"<br>");//输出数据
      Line = br.readLine(); //自文件读取一行数据
      }
    br.close(); //关闭BufferedReader变量
    fr.close(); //关闭文件
    }
    }catch(Exception ex)

    throw new ServletException(ex.getMessage()); 
    } %> 
    </center> 
    </body> 
    </html>
    现在就是如何将文件里的内容掉回显示在列表框里:
    <select name="textSelect" size="8"  class=self style="WIDTH:93%" height="20">
        </select>在线等带你们4人组的回复 谢谢 我相信你们4人组 一定能解决的 谢谢!!!
      

  3.   

    楼上的 你也别生气 了真的 我又是个新手 !!我看了你们的 程序 主要还是在那个 动太页里啊 可是我真的 不只如何 来掉啊 
    我原本不做任何修改 用下面的语句:
    <script language=javascript>
    var returnArray = new Array();
    returnArray[1] = 111;
    returnArray[0] = 222;//这里的值应该怎么填?
    parent.window.returnValue=returnArray;
    parent.window.close();
    </script>
    可是一按 读号码 弹出窗口就闪 了一下 !然后列表里的值 都是222 不好意思 让你们烦心了 我是个新手 的确 理解上 有点难度啊 望见谅!!!
      

  4.   

    ——————————————————duanxinfasong.html————————————————
    <html>
    <head>
    <meta http-equiv="Content-Language" content="zh-cn">
    <link href='../../css/css.css' rel='stylesheet' type='text/css'>
    <script language="JavaScript">
    function NewWindow()
    { //*******************更改开始*******************************
    //window.open("http://car.wap888.cn/jspwen/fuwu/ziyouduanxin/tijao.html","","height=200,width=350,left=10,top=10,status=no,location=no,toolbar=no, directories=no,menubar=no");
    var args;
    var Height = 60;
    var Width = 450;
    strStyle = "help:no;"+
    "minimize:no;" +
    "maximize:no;" + 
    "border:thick;" +
    "statusbar:no;" +
    "dialogWidth:"+Width+"px;" +
    "scroll:no;" +
    "dialogHeight:"+Height+"px;" +
    "center:yes;" +
    "status:no;" +
    "edge: raised";
    args = window.showModalDialog("frametijao.htm","",strStyle);//要加一个框架页,名字叫frametijao
    if(typeof(args)=="object"){
    var oOption = document.createElement("OPTION");
    document.all.textSelect.options.add(oOption);
    oOption.value = args[1];
    oOption.innerText = args[0];
    document.all.textSelect.selectedIndex = oOption.index;
    } //*******************更改结束*******************************
    }function addOption(){   var sjh=document.form1.T1.value;
       if(isNaN(sjh))
      {
      alert("你输入的手机号码不是数字!");
      return(false);
      }
    if(sjh=="")
      {
          alert("不能输入空值!");
      return(false);
    }
      if(sjh.indexOf("13")==-1)
      {
        alert("你输入的不是13开头的手机号!");
    return(false);
      }
      if(sjh.length!=11)
      {
        alert("你输入的手机号不是11位!");
    return(false);
      }
    else {    addValue=document.form1.T1.value;
    var option=document.createElement("OPTION");
    option.value=addValue;
    option.text=addValue;
    form1.textSelect.add(option)
    }
    }
    function doSubmit(){
        var phaseString = "";
        var optionsArray = document.all("textSelect").children;
        var selectString="";
        for (var i = 0 ; i < optionsArray.length ; i++){
            selectString = selectString + phaseString + optionsArray[i].value;
        }
        document.all("selectValue").value=selectString;
    }
    function clear_text1()//清空
    {
    var textSelect;
     while(Number(form1.textSelect.options.length) > 0) 
     {
    form1.textSelect.options.remove(Number(form1.textSelect.options.length-1));// 这样试试
    }
    }
    function clear_text2()//删除
    {
    try{
    for(var i=0;i<form1.textSelect.options.length;i++)
    {
    if(form1.textSelect.options[i].selected)
    {
      form1.textSelect.remove(i);
      i=i-1;
    }
    }

    }
    catch(e){}
    }
    </script>
    <script>
    function chklen()
    {
    len=0;
    for(var begin = 0; begin < document.form1.S2.value.length; begin++)
    {

    len+=1;
    }
    len=70-len;
    if(len>=0)
    {
    tno.innerText = len;
            tno.style.color = "ff0000";
    }
    else
    {
    tno.innerText = ",不对,应该删去" + -(len);
    tno.style.color = "ff0000"; }
    }
    function checklen()
    {
    if(len<0)
    {
    alert("\内容超长" + -(len) + "个字,请修改 !!")
    return(false);
    }
    return(true);
    }
    document.onkeyup=chklen;
    </script>
    <script language="javascript">
    function check(){
    var t1=document.form1.textSelect.value;var d6=document.form1.S2.value;
    if( t1=="" && d6=="")
    {
    alert("不能空值发送数据请输入数据后再发!");
    return false;
    }
      
    } </script>
    </head>
    <form method="POST" action="dxfspost.jsp" name="form1"  ><table border="0" cellpadding="0" cellspacing="0" width="629" height="397" bgcolor="#999999" cellspacing="1">
    <tr>
    <td valign="top" height="53" width="90" bgcolor="#FDFAFB">

    <p align="center">
    <input type=image src="../../../images/shezhi/changjia.jpg" name=submit width="32" height="32" onclick="check();doSubmit();"><input type="hidden" value="" name="selectValue"><br>
    立即发送</td>
    <td valign="top" height="53" width="69" bgcolor="#FDFAFB">
        <p align="center">
    <input type=image src="../../../images/fuwu/freesms.jpg" width="32" height="32" name=reset><br>
    重新输入</td>
    <td valign="top" height="53" width="72" bgcolor="#FDFAFB">

    <p align="center">
    <img border="0" src="../../../images/shezhi/system.jpg" width="33" height="35"><br>
    关闭</td>
    <td valign="top" height="53" width="319" bgcolor="#FDFAFB">

     </td>
    </tr>
    <tr>
    <td valign="top" height="31" width="629" colspan="5" bgcolor="#FDFAFB">

    <p>&nbsp;&nbsp; 号码:<input class="bbox"  type="text" name="T1" size="20" autocomplete=off>&nbsp;<input class="bbox"  type="button" onClick="javascript:addOption();" value="增加">&nbsp;
    <input class="bbox"  type="button" value="读号码" ONCLICK="NewWindow()" >&nbsp;
    <input class="bbox"  type="button" value="删除" name="B3" onClick="javascript:clear_text2();">&nbsp;
    <input class="bbox"  type="reset" value="清空" name="B4" onClick="javascript:clear_text1();"></p>
    </td>
    </tr>
    <tr>
      <td valign="top" width="629" colspan="5" bgcolor="#FDFAFB">
      <p align="center">
    <select name="textSelect" size="8"  class=self style="WIDTH:93%" height="20">
        </select>

      </td>
    </tr>
    <tr>
    <td valign="top" width="629" colspan="5" height="12" bgcolor="#FDFAFB">

    <p align="center"><b><font size="3">发送内容</font></b>

    </tr>
    <tr>
    <td valign="top" width="629" colspan="5" height="137" bgcolor="#FDFAFB"> <p align="center">
    <textarea class=self rows="10" name="S2" cols="112" maxlength=""></textarea>
    </td>
    </tr>
    <tr>
    <td  bgcolor="#FDFAFB"  width="629" colspan="5">
    <p align="center">注意:    
    注意:您的短信内容还可输入<span id="tno">70</span>个字。
    </td> </tr>
    <tr><td bgcolor="#FDFAFB"  height=100 colspan=5></td></tr>
    </table>
    </form>
    </html>
    主窗口中 读号码 按纽 弹出的窗口代码:——————————————frametijao.html——————————————————
    <html>
    <head>
    <title>附件管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head>
    <frameset rows="*,0" frameborder="NO" border="0" framespacing="0"> 
      <frame name="topFrame" scrolling="NO" noresize src="tijao.html">
      <frame name="mainFrame" src="#">
    </frameset>
    <noframes> 
    <body bgcolor="#FFFFFF" text="#000000">
    </body>
    </noframes> 
    </html>——————————————tijao.html—————(不变)—————————————
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta NAME="Generator" CONTENT="EditPlus">
    <meta NAME="Author" CONTENT="">
    <meta NAME="Keywords" CONTENT="">
    <meta NAME="Description" CONTENT="">
    </head>
    <body bgcolor="#FDFAFB">
    <br>
    <br>
    <br>
    <center>
    <form name=form1 action="uploadpost.jsp"  method="POST" enctype="multipart/form-data"><table border="0" bgcolor="#F4F8FE" cellpadding="0" cellspacing="1" >
    <tr bgColor=#ffffff>
    <td>文件名</td>
    <td><input type="file" name="file" ></td></tr>
    <tr>
    <td><input type="submit" value="确定" </td></tr>
    <tr>
    <td colspan="2" height="20"><div align="center">请按规定上传文本(.txt)文件</div></td>
    </tr>
    </table>
    </form>
    </center>
    </body>
    </html>
      

  5.   

    ——————————————————action="uploadpost.jsp"————————————
    <%@ page contentType="text/html; charset=gb2312" %> 
    <%@ page language="java" %>
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*"%> 
    <%@ page import="java.util.*"%> 
    <%@ page import="javax.servlet.*"%> 
    <%@ page import="javax.servlet.http.*"%> 
    <html> 
    <head> 
    <title> 
    万科 
    </title> 
    </head> 
    <body bgcolor="#ffffff"> 
    <center> 
    <% 
    int n=0;
    int MAX_SIZE = 102400 * 102400;//定义上载文件的最大字节 
    String rootPath; // 创建根路径的保存变量
    DataInputStream in = null; //声明文件读入类
    FileOutputStream fileOut = null; 
    String remoteAddr = request.getRemoteAddr();//取得客户端的网络地址IP 
    out.print(remoteAddr); 
    out.print("<br>");
    String serverName = request.getServerName(); //获得服务器的名字 
    %>你访问的网站是:<%out.print(serverName); 
    out.print("<br>");
    //取得jsp文件相对与根地址的地址 
    out.print(request.getServletPath()); 
    out.print("<br>");
    String realPath = request.getRealPath(serverName); //取得互联网程序的绝对地址
    /out.println(realPath); 
    out.print("<br>");
    realPath = realPath.substring(0,realPath.lastIndexOf("\\")); 
    out.print(realPath); 
    rootPath = realPath + "\\upload\\"; //创建文件的保存目录upload
    %>传到服务器上的路径是:<% out.println(rootPath); String contentType = request.getContentType(); //取得客户端上传的数据类型 
    out.println("<p>客户端上传的数据类型 = " + contentType + "</p>"); 
    try{ 
    /*if(contentType != null && contentType.indexOf("multipart/form-data") >= 0)
    { */
    //读入上传的数据 
    in = new DataInputStream(request.getInputStream()); 
    int formDataLength=request.getContentLength(); 
    if(formDataLength > MAX_SIZE){ 
    out.print("<P>上传的文件字节数不可以超过"+ MAX_SIZE + "</p>"); 
    return; 

    //保存上传文件的数据 
    byte dataBytes[] = new byte[formDataLength];//放在一个字符数组里 
    int byteRead = 0; 
    int totalBytesRead = 0; 
    //上传的数据保存在byte数组 
    while(totalBytesRead < formDataLength)

    byteRead = in.read(dataBytes,totalBytesRead,formDataLength); 
    totalBytesRead += byteRead; 

    //根据byte数组创建字符串 
    String file = new String(dataBytes); 
    //out.println(file); 
    //取得上传的数据的文件名 
    String saveFile = file.substring(file.indexOf("filename=\"") + 10); 
    saveFile = saveFile.substring(0,saveFile.indexOf("\n")); 
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\")+1,saveFile.indexOf("\"")); 
    int lastIndex = contentType.lastIndexOf("="); 
    //取得数据的分隔字符串 
    String boundary = contentType.substring(lastIndex + 1,contentType.length()); 
    //创建保存路径的文件名 
    String fileName = rootPath + saveFile; 
    //out.print(fileName); 
    int pos; 
    pos = file.indexOf("filename=\""); 
    pos = file.indexOf("\n",pos) + 1; 
    pos = file.indexOf("\n",pos) + 1; 
    pos = file.indexOf("\n",pos) + 1; 
    int boundaryLocation = file.indexOf(boundary,pos) - 4; 
    //out.println(boundaryLocation); 
    //取得文件数据的开始的位置 
    int startPos =((file.substring(0,pos)).getBytes()).length; 
    //out.println(startPos); 
    //取得文件数据的结束的位置 
    int endPos = ((file.substring(0,boundaryLocation)).getBytes()).length; 
    //out.println(endPos); 
    //检查上载文件是否存在 
    File checkFile = new File(fileName); 
    if(saveFile.indexOf(".txt")<0)
    {
    out.print("<p>你上传的文件不是文本文件!</p>");
    }
    else {
    if(checkFile.exists())

    out.println("<p>" + saveFile + "文件已经存在.</p>"); 

    //检查上载文件的目录是否存在 
    File fileDir = new File(rootPath); 
    if(!fileDir.exists())

    fileDir.mkdirs(); 

    //创建文件的写出类 
    fileOut = new FileOutputStream(fileName); 
    //保存文件的数据 
    fileOut.write(dataBytes,startPos,(endPos - startPos)); 
    fileOut.close(); 
    out.println("<P>" + saveFile + "文件成功上载.</p>"); 
    /*}else{ 
    String content = request.getContentType(); 
    out.println
    ("<p>上传的数据类型不是是multipart/form-data</p>"); 
    } */
    %>上传的文件内容是:<br><%
     FileReader fr=new FileReader(rootPath +saveFile);
    //建立BufferedReader变量, 并设定由br变量引用
       BufferedReader br=new BufferedReader(fr);
    //自文件读取一行字串
       String Line=br.readLine();
        while(Line!=null)
      {
     out.print(Line+"<br>");//输出数据
      Line = br.readLine(); //自文件读取一行数据
      }
    br.close(); //关闭BufferedReader变量
    fr.close(); //关闭文件
    }
    }catch(Exception ex)

    throw new ServletException(ex.getMessage()); 
    } out.print("<script language=javascript>"
    out.print("var returnArray = new Array();")
    out.print("returnArray[1] ="+ Line +";");
    out.print("returnArray[0] ="+ Line +";");</script>%> 
    </center> 
    <script language=javascript>
    parent.window.returnValue=returnArray;
    parent.window.close();
    </script>
    </body> 
    </html>
      

  6.   

    friendlyFour 你们好 :
      真的万分感谢你们 那个问题解决了 真的很感谢你们
      我是个新手 所以在问题上给你们添麻烦了 真的感到很抱歉 希望你们原谅
      程序稍加修改了一下
      我冒昧的再向你们请教个问题 发现:这个程序不能实现批量导出数据
      好象只能导入文本文件里的最后一个数据!比如我的文本文件名23.txt里面的数据
    是这样的:
    13912176876
    13697246477
    13856425868
    我按 读号码 按纽 在弹出窗口选者23.txt 上传后按确定 后将里面的数据掉回显示
    在列表框里只有一个数据却是最后的一行数据13856425868 就好象一次只能导入一
    个数据不能批量导出!!不只是不是我的那行代码写错了还是 
    所以我冒昧的再请你们看看我修改后的代码:
    //自文件读取一行字串
       String Line=br.readLine();
        while(Line!=null)
      { 
    out.print("<script language=javascript>");
    out.print("var returnArray = new Array();");
    out.print("returnArray[1] ="+ Line +";");
    out.print("returnArray[0] ="+ Line +";");
        out.print("</script>");
        Line = br.readLine(); //自文件读取一行数据
      }
    br.close(); //关闭BufferedReader变量
    fr.close(); //关闭文件
    }
    }catch(Exception ex)

    throw new ServletException(ex.getMessage()); 

    %> 
    </center> 
    <script language=javascript>
    parent.window.returnValue=returnArray;
    parent.window.close();
    </script>
    真的很抱歉 又麻烦你们4位了 
    我也希望以后 能多多向4位前辈请教!!
    我等待你们的回复
    我邮箱:
    [email protected]
      

  7.   

    try
    ----------------   
       String Line=br.readLine();
       out.print("<script language=javascript>");
       out.print("var returnArray = new Array();");
       int i = 0;
       while(Line!=null)
       { 
          out.print("returnArray["+i+"] ="+ Line +";");
          Line = br.readLine(); //自文件读取一行数据
          i++
       }
       out.print("</script>");