jquery 取得文件根目录
function getRootPath() {
//获得根目录
var strFullPath = window.document.location.href
var strPath = window.document.location.pathname
var pos = strFullPath.indexOf(strPath)
var prePath = strFullPath.substring(0, pos)
var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1)
return (prePath + postPath)
}
给题主几个关键字:HTML5,FileReader,FileList,readAsText
Jquery跟读取本地文本文件没有一点关系,jquery没这个功能,能做到的只有HTML5的fileReader(当然你要说IE的话当我没说)。使用的时候考虑下兼容性。
ps.最后再吐槽下题主的问题,如果你悬赏了很高的分数,我就不说啥了。关键是一分没有,没弄清楚问题,还“回答之前先调试”,别这么高傲好吧,别人给你思路就已经足够你解决问题了。
http://hi.baidu.com/xiaogangcoolba/blog/item/d6ac2259c9e41d8d800a18f3.html资料来源
<%@ page contentType="text/xmlcharset=UTF-8"%>
<%@ page language="java"%>
<%@ page
import="org.apache.commons.httpclient.*,org.apache.commons.httpclient.methods.GetMethod"%>
<%@ page import="java.io.*"%>
<%
out.clear()//清空当前的输出内容(空格和换行符)
//String url = request.getParameter("url") //获取URL地址
String url = "http://www.google.com/ig/api?hl=zh-cn&weather=,,,30670000,104019996"
HttpClient client = new HttpClient()//创建Http客户端对象
GetMethod method = new GetMethod(url)//创建一个Get请求方法
try {
client.executeMethod(method)//执行Get请求方法
//下面10行是解决当返回数据文件较大时处理
InputStream resStream = method.getResponseBodyAsStream()
BufferedReader br = new BufferedReader(new InputStreamReader(
resStream))
StringBuffer resBuffer = new StringBuffer()
String resTemp = ""
while ((resTemp = br.readLine()) != null) {
resBuffer.append(resTemp)
}
String responsexml = resBuffer.toString()
out.print(responsexml)
//下面本来可以直接获取到xml内容,但是当文件较大时会报警告
//out.print(method.getResponseBodyAsString())//将获取的结果输出到响应体
} catch (Exception e) {
} finally {
method.releaseConnection()//释放Http连接
}
%>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)