上传文件
三、接收文件
request.setCharacterEncoding("UTF-8");
// 文件保存路径
String path = request.getSession ().getServletContext ().getRealPath ("/")
+"tmp_jkhd_booking\\aa.pdf";
// +request.getParameter("filename");
InputStream is = request.getInputStream();
OutputStream os = new FileOutputStream(path);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = is.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
四、接收流
strust1
InputStreamReader isr = null;
BufferedReader bf = null;
StringBuffer protocolXML = new StringBuffer("");
try {
String s = "";
request.setCharacterEncoding("UTF-8");
isr = new InputStreamReader(request.getInputStream(), "UTF-8");
bf = new BufferedReader(isr);
while((s = bf.readLine())!=null){
protocolXML.append(s);
}
bf.close();
isr.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
bf.close();
isr.close();
}
strust2
public String doUploadMapFile (@RequestParam (value = "uploadfile", required = false) MultipartFile uploadfile, HttpServletRequest request) {
Map <String, Object> data = new HashMap <String, Object> ();
boolean result = Boolean.TRUE;
// 定义容器接收文件名
String uploadFileName = null;
try
{
InputStreamReader read = new InputStreamReader (uploadfile.getInputStream (), "utf-8");// 考虑到编码格式
BufferedReader bufferedReader = new BufferedReader (read);
StringBuffer jsonContent = new StringBuffer ();
String content = "";
while ((content = bufferedReader.readLine ()) != null)
{
jsonContent.append (content);
}
String brProjectPath = request.getSession ().getServletContext ().getRealPath ("/");
uploadFileName = uploadfile.getOriginalFilename ();
// 文件保存路径
String filePath = brProjectPath + "map\\" + uploadFileName;
File date = new File (filePath);
FileOutputStream fop = null;
fop = new FileOutputStream (date);
byte[] contentInBytes = jsonContent.toString ().getBytes ();
fop.write (contentInBytes);
fop.flush ();
fop.close ();
read.close ();
一、预览图片(blob)
<div>
<input class="easyui-filebox"
labelPosition="top"
data-options="buttonText:'选择文件', accept:'application/pdf',onChange:function(){view_file(this)} "
style="width:90%">
<div>
<div style="margin-top:20px">
<a href="#" class="easyui-linkbutton" style="width:30%" onclick="upload_file()">预约</a>
<img id="pdf_view"></img>
</div>
// 上传时,触发的事件
function view_file(_obj) {
// 获取当前上传的file的路径
var _filepath = $(_obj).filebox("getValue");
var _file = document.getElementById('filebox_file_id_1').files[0];
$('#pdf_view').attr("src", getObjectURL(_file))
}
// 获取file的本地浏览器对应路径
function getObjectURL(_file) {
var url = null;
if (window.createObjectURL != undefined) {
url = window.createObjectURL(_file);
} else if (window.URL != undefined) {
url = window.URL.createObjectURL(_file);
} else if (window.webkitURL != undefined) {
url = window.webkitURL.createObjectURL(_file);
}
return url;
}
二、pdf 预览(jquery.metadata.js)
http://jquery.malsup.com/media/
http://jquery.malsup.com/media/misc.html
<script type="text/javascript" src="http://github.com/malsup/media/raw/master/jquery.media.js?v0.92"></script>
<script type="text/javascript" src="jquery.metadata.js"></script>
...
<a class="media" href="guice.pdf">PDF File</a>
<a class="media {type: 'html'}" href="../">HTML File</a>

浙公网安备 33010602011771号