开发一个j2ee应用部署在web服务器上,在应用中实现一个文件内容显示的jsp页面,要求如下:  
1有一个List下拉列表菜单,列表中的每项内容对应web服务器上的一个文本文件,
2当List列表菜单的内容改变时触发onChange()事件,在事件中完成列表文件内容的读取并将内容显示在jsp页面的相应位置。
[email protected]

解决方案 »

  1.   

    用google找下吧,应该很多的,呵呵
      

  2.   

    就是因为没有google到
    自己再顶一下
      

  3.   

    <%@ page contentType="text/html; charset=GBK" language="java"%>
    <%@ page import="java.io.*,java.util.*"%>
    <%
    request.setCharacterEncoding("GBK") ;
    Properties p = System.getProperties() ;
    String tomcat_bin = p.getProperty("user.dir") ; //取得Tomcat的bin目录
    String dirpath = tomcat_bin+"\\..\\webapps\\test\\test" ; //这里加上你的文件所在目录
    File f = new File(dirpath);File[] files = null;if(f.exists())
    {
    files = f.listFiles() ;
    }%>
    <select name="file" onchange="read(this.value)">
    <option id="-1" value="">please select one file....</option>
    <%
    if(files  != null)
    {
    for(int i=0; i<files.length; i++)
    {
    %>
    <option id="<%=i%>" value="<%=files[i].getAbsoluteFile()%>"><%=files[i].getName()%></option>
    <%}}%>
    </select><%
    String currentfile = request.getParameter("file") ; //当前选择的文件if(currentfile != null && currentfile.length() > 0)
    {
    File f1 = new File(currentfile) ; if(f1.exists())
    {
    out.println("<p>您当前选择的文件是:"+currentfile+"</p>");
      BufferedReader br = new BufferedReader(new FileReader(currentfile)) ;
      out.println("<p>");
      String ss;
      while((ss = br.readLine()) != null)
      {
         out.print(ss);
         out.print("<br />");
      }
      out.println("</p>");
    }
    }
    %>
    <script>
    function read(s)
    {
    location.href="c.jsp?file="+s ;
    }
    </script>
      

  4.   

    大侠:
    我现在用的是websphere,不是tomcat
    以下两行需要怎么改?谢谢!!String tomcat_bin = p.getProperty("user.dir") ; //取得Tomcat的bin目录
    String dirpath = tomcat_bin+"\\..\\webapps\\test\\test" ; //这里加上你的文件所在目录
      

  5.   

    这个dirpath可以写死如果你是windows系统就写要遍历的目录的绝对路径,如 c:\\websphere\\webapps\\file
    如果是unix 就是/usr/webser/........试试
      

  6.   


    我的文件路径是C:\Program Files\IBM1\WebSphere\AppServer\logfiles我像下面这样写,但是在list里找不到我需要的文件
    String web_bin = p.getProperty("user.dir"); 
    String dirpath = web_bin+"C:\\Program Files\\IBM1\\WebSphere\\AppServer\\logfiles";高手帮我看看啊!谢谢了
      

  7.   

    不要第一句直接使用
    String dirpath = "C:\\Program Files\\IBM1\\WebSphere\\AppServer\\logfiles";
    搞定记得结贴 (:
      

  8.   

    老大,还是不行啊
    list只能显示:please select one file...
    怎么办啊?
      

  9.   

    你是要查看logfiles下的所有文件吧?
      

  10.   

    现在list中能显示文件了,但是我在list中选择一个文件后报错如下。高手帮忙啊!
    JSP 处理错误HTTP 错误代码:   404错误消息:JSPG0036E: 无法找到资源 /c.jsp
     
    根本原因:java.io.FileNotFoundException: JSPG0036E: 无法找到资源 /c.jsp at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.findWrapper(JSPExtensionProcessor.java:268) at com.ibm.ws.jsp.webcontainerext.JSPExtensionProcessor.handleRequest(JSPExtensionProcessor.java:250) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2965) at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:221) at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:210) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1931) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:84) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:472) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:411) at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:101) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:566) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java(Compiled Code)) at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:952) at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1039) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
     
      

  11.   

    String dirpath = "C:\\Program Files\\IBM\\WebSphere\\AppServer\\logfiles" 刚才又试了String dirpath = "C:/Program Files/IBM/WebSphere/AppServer/logfiles" 
    也报错
      

  12.   

    现在list中能显示文件了,但是我在list中选择一个文件后报错如下。高手帮忙啊!-----------------
    你不是说可以在list中列出所有文件了吗?我问的就是你的每个<option>中的value是怎么赋值的,看看
      

  13.   

    错误消息:JSPG0036E: 无法找到资源 /c.jsp
    是不是这一段有问题啊? function read(s)
    {
    location.href="c.jsp?file="+s ;
    }
      

  14.   

    晕啊,你的当前的jsp文件名叫什么?那个c.jsp是我测试用的页面,你至少也改一下,改成你的文件名吧,呵呵
      

  15.   

    windows环境下,文件路径应该怎么写?
    String dirpath = "C:\\Program Files\\IBM\\WebSphere\\AppServer\\logfiles" String dirpath = "C:/Program Files/IBM/WebSphere/AppServer/logfiles"