a.html建议放置在assets文件夹下,加载url的写法是:file://android_assets/a.html
可以尝试新建asstes文件夹,Android Studio手动创建asstes路径:src/main/asstes,Eclipse手动创建项目目录下
这个问题涉及到HTML编码。虽然不十分复杂,但一句话两句话却很难说清。基本的解决思路就是修改HTML源文件里的图片调用地址代码。建议百度搜索HTML教程,找到图片调用部分了解一下。如果不想研究HTML,只想就事论事简单解决一下,可以尝试用右键文本方式打开HTML源文件,找到IMG SRC=后面的地址,更换成本地电脑里的文件夹(路径)
html中file上传后保存到一个位置需要预先在服务端建一个保存目录。
举例如下:
1、创建上传form:
<form action="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi"
enctype="multipart/form-data" method="post">
<p>
Type some text (if you like):<br>
<input type="text" name="textline" size="30">
</p>
<p>
Please specify a file, or a set of files:<br>
<input type="file" name="datafile" size="40">
</p>
<div>
<input type="submit" value="Send">
</div>
</form>
2、提交到后台服务端处理:
public void commonImgUpload(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/xml charset=utf-8")
response.setCharacterEncoding("UTF-8")
PrintWriter pw = response.getWriter()
String xml = ""
String imgName = getParam(request, "imgName")
String imgValue = getParam(request, "imgValue")
String type = getParam(request, "type")
String encryptCode = getParam(request, "encryptCode")
log.debug("图片上传,图片名称:" + imgName + ",上传类型:" + type)
if (MD5Checker.check(encryptCode, imgName)) {
try {
String path = this.getClass().getClassLoader().getResource("").getPath()
log.info("当前路径:" + path)
path = path.replace("WEB-INF/classes/", "pictures/" + type + "/")
log.info("替换后路径:" + path)
File temp = new File(path)
if (!temp.isDirectory()) {
log.info("创建目录path: " + path)
temp.mkdirs()
}
path += imgName
log.info("图片全path: " + path)
FileUtil.saveFile(path, (new BASE64Decoder()).decodeBuffer(imgValue), "UTF-8")
xml = "success"
log.info("上传图片:" + path + "成功!")
} catch (Exception e) {
log.info("上传图片失败," + e.getMessage())
xml = "fail"
}
} else {
xml = "<data><resultCode>" + "09" + "</resultCode>" + "<resultMsg>" + "摘要验证错误" + "</resultMsg>" + "</data>"
}
pw.print(xml)
if (null != pw) {
pw.close()
}
}
3、保存路径:
WEB-INF/classes/pictures/111.jpg
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)