应客户要求,本身很简单的问题。现在有点棘手了。功能简单说一下。类似各大网站注册时候或者第一次进入大型游戏的时候,会有条约同意画面。现在这个画面里面的内容是以txt保存的。我需要做的是读取数据库里的这个txt文件的路径之后,然后返回到jsp页面动态的读取这个txt文件的内容。现在问题就是,因为是动态的,我一开始用textarea+include写死了就用不了了。现在路径已读取出来,不知道如何在页面上获取这个路径并展示出来。求指教。

解决方案 »

  1.   

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head><head><body>
       <iframe src="" id="id" frameborder="1" height="100" width="200"></iframe>
      
      
        <script type="text/javascript">
       function aa(){
       
       var ss = document.getElementById("id");
       ss.src ="${url}";//用el表达式动态加载url
       
       }
    window.load = aa();
    </script>
    <body>
    </html>
      

  2.   

    可以使用ssi 或者 FileInputStream
    public static String readFile() throws IOException, FileNotFoundException {
        File textFile = new File(textFilePath);
        if(!textFile.exists()){
            throw new FileNotFoundException(textFilePath + "文件不存在");
        }
        InputStream in = new FileInputStream(textFile);
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuffer buf = new StringBuffer(textFile.length()/2);
        String line = null;
        while((line = in.readLine()) != null){
            buf.append(line).append("\n");
        }
        reader.close();
        in.close();
        return buf.toString();
    }
      

  3.   

    我就觉得先用一段程序读出txt中的数据,可以保存成String了,然后再将该String传递到jsp页面中了,在输出来。当然txt中的类容就可以是动态的了。
      

  4.   


    是好招, 但是要注意路径建议在服务器端读出打印出来, 如果需要减少http请求数的话
      

  5.   

    是我的话我就每次先读出内容再传给jsp
      

  6.   

    用ajax操作,要是你的txt是有规律的可以用 一个xml格式将数据传给前台jsp页面,之后通过ajax将xml解析,同时拼装成一个jsp插入到你的目的div中。。即可