response.flush,JS判断页面是否加载完成?
1,html与js是否是并行下载 如果你想问的是,在 页面 HTML 加载完成之前,浏览器是不是会加载外联 js ,那么是的,你可以拿 Node.js 写一个 request handler ,在多次 flush 之间弄一个时间间隔试试。
2,是js的下载阻塞了页面的渲染还是js的执行阻塞了页面的渲染,还是两者都会阻塞页面DOM 树解析到非异步的外联 js 时会阻塞住,在它加载并且执行完之前,不会往下解析 DOM 树。
3,script标签放在head中与放在body中,是影响了js的下载开始时间还是执行开始时间 如果不考虑 http 并发请求数的限制,并且忽略掉接收页面 response body 的耗时的话,在有预解析的浏览器上,外联的 script 放哪都不会(太)影响加载开始时间。需要注意的是,虽然加载是并行化的,但 js 会阻塞住 dom 树解析,因而你把 script[src]放在 head 中会阻塞住首屏渲染,最好还是放在 body 尾部。
4,css,图片以及一些其它的外部资源的下载是否与html,js的下载并行情况还挺复杂的,基本上指导原则是浏览器会尝试把所有的加载都并行化,尽可能快地完成加载,但也要考虑并发请求数的限制。并且如上一条所述,并行化加载,但 dom 树解析、js执行和首屏渲染却是串行的,浏览器会尽可能快地完成加载,不代表这些元素放置的顺序就不重要。
在android开发中?
效果:layout界面布局:[html] view plaincopyprint?<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:ad="http://schemas.android.com/apk/res/android"ad:layout_width="match_parent"ad:layout_height="match_parent"ad:orientation="vertical" ><LinearLayoutad:layout_width="match_parent"ad:layout_height="30dp"ad:background="@drawable/titlebar_bg"ad:orientation="horizontal" ><ImageViewad:layout_width="wrap_content"ad:layout_height="wrap_content"ad:src="@drawable/back_44_44" /><LinearLayoutad:layout_width="match_parent"ad:layout_height="30dp"ad:gravity="center" ><TextViewad:layout_width="wrap_content"ad:layout_height="wrap_content"ad:text="课程列表"ad:textSize="20sp" /></LinearLayout></LinearLayout><ScrollViewad:id="@+id/ScrollView"ad:layout_width="fill_parent"ad:layout_height="wrap_content"ad:scrollbars="vertical" ><LinearLayoutad:id="@+id/mainLayout"ad:layout_width="match_parent"ad:layout_height="wrap_content"ad:orientation="vertical" ></LinearLayout></ScrollView></LinearLayout>httputil辅助类:
[java] view plaincopyprint?package com.tudou.activity.work4;import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import android.util.Log;public class HttpUtil {/*** 获取到流,自己处理数据* @param path* @return*/public static InputStream getInputStream(String path) {HttpURLConnection conn = null;try {URL url = new URL(path);conn = (HttpURLConnection) url.openConnection();conn.setDoInput(true);// 设置是否向httpUrlConnection输出,post请求,参数要放在http正文内conn.setDoOutput(true);conn.setReadTimeout(3000);conn.setConnectTimeout(3000);conn.setUseCaches(false);conn.setRequestMethod("POST");if (conn.getResponseCode() == 200) {Log.d("mylog", "getResponseCode:" + 200);return conn.getInputStream();}} catch (IOException e) {e.printStackTrace();} finally {if (conn != null) {conn.disconnect();}}return null;}/*** 直接返回响应体正文* @param path* @return*/public static String getResponseBody(String path,String params) {HttpURLConnection conn = null;StringBuffer result=new StringBuffer()
;try {URL url = new URL(path);conn = (HttpURLConnection) url.openConnection();conn.setDoInput(true);// 设置是否向httpUrlConnection输出,post请求,参数要放在http正文内conn.setDoOutput(true);conn.setReadTimeout(3000);conn.setConnectTimeout(3000);conn.setUseCaches(false);conn.setRequestMethod("POST");//数据输出流,该语句隐含的执行connect动作if(params!=null){DataOutputStream out = new DataOutputStream( conn.getOutputStream());//将参数写入流,刷新提交关闭流out.writeBytes(params);out.flush();out.close();}//读取连接返回的数据BufferedReader reader = new BufferedReader(new InputStreamReader( conn.getInputStream()));String inputLine = null;while (((inputLine = reader.readLine()) != null)) {result.append(inputLine);//"\n";}//关闭reader.close();if (conn.getResponseCode() == 200) {Log.d("mylog", "getResponseCode:" + 200);}} catch (IOException e) {e.printStackTrace();} finally {if (conn != null) {conn.disconnect();}}return result.toString();}}主activity:[java] view plaincopyprint?package com.tudou.activity.work4;import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;import com.tudou.activity.R;import android.app.Activity;import android.graphics.Color;import android.os.Bundle;import android.util.Log;import android.util.TypedValue;import android.view.Gravity;import android.view.ViewGroup;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.LinearLayout.LayoutParams;import android.widget.ProgressBar;import android.widget.TextView;public class HomeWork4 extends Activity {String path = "此处省略,你要请求的地址";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.homework4);LinearLayout mainLayout = (LinearLayout)findViewById(R.id.mainLayout);String result=HttpUtil.getResponseBody(path,null);// Log.d("mylog", "result:" + result);try{JSONObject obj = new JSONObject(result);JSONArray array=obj.getJSONArray("onlineCourses");for (int i = 0; i < array.length(); i++) {JSONObject course= array.getJSONObject(i);// Log.d("mylog", "course:" + course.toString());//添加左边的layoutLinearLayout leftlayout=new LinearLayout(this);//注意包android.widget.LinearLayout.LayoutParams,其它包下面的LayoutParams不起作用LayoutParams params=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);params.topMargin=10;leftlayout.setLayoutParams(params);leftlayout.setOrientation(LinearLayout.HORIZONTAL);leftlayout.setGravity(Gravity.CENTER_VERTICAL);//添加左边layout的图片ImageView imageView=new ImageView(this);params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);imageView.setLayoutParams(params);imageView.setImageResource(R.drawable.image_default_195_130);leftlayout.addView(imageView);//添加右边的layout,分为上下2部分,上面是标题,下面是进度条LinearLayout rightlayout=new LinearLayout(this);LayoutParams rightLayoutParams=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);rightlayout.setLayoutParams(rightLayoutParams);rightlayout.setOrientation(LinearLayout.VERTICAL);//添加课程标题TextView textView=new TextView(this);params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);textView.setLayoutParams(params);textView.setText(course.get("courseName").toString());textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);//18SP//学分,水平布局,分为左右,左:学分,,右:分值LinearLayout studyLayout=new LinearLayout(this);params=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);studyLayout.setLayoutParams(params);studyLayout.setOrientation(LinearLayout.HORIZONTAL);//添加学分TextView studyView=new TextView(this);params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);studyView.setLayoutParams(params);studyView.setText("学分:");studyView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);studyView.setTextColor(Color.parseColor("#b6b6b6"));//第2种方法:setTextColor(Color.rgb(255, 255, 255));//添加学分值TextView studyValueView=new TextView(this);params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);studyValueView.setLayoutParams(params);studyValueView.setText(course.get("courseCredit").toString());studyValueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);//进度条,水平布局,分为左中右,左:学习进度,中:进度条,右:%值LinearLayout processLayout=new LinearLayout(this);params=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);processLayout.setLayoutParams(params);processLayout.setOrientation(LinearLayout.HORIZONTAL);//添加学习进度TextView processtextView=new TextView(this);params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);processtextView.setLayoutParams(params);processtextView.setText("学习进度:");processtextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);processtextView.setTextColor(Color.parseColor("#b6b6b6"));//添加进度条ProgressBar bar=new ProgressBar(this,null,android.R.attr.progressBarStyleHorizontal);//指定进度条样式params=new LayoutParams(150, ViewGroup.LayoutParams.WRAP_CONTENT);bar.setLayoutParams(params);bar.setMax(100);bar.setProgress(10);//添加%值TextView processvaluetextView=new TextView(this);params=new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);processvaluetextView.setLayoutParams(params);processvaluetextView.setText("10%");processvaluetextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);processvaluetextView.setTextColor(Color.parseColor("#b6b6b6"));//添加标题rightlayout.addView(textView);//添加学分studyLayout.addView(studyView);studyLayout.addView(studyValueView);rightlayout.addView(studyLayout);//添加进度条processLayout.addView(processtextView);processLayout.addView(bar);processLayout.addView(processvaluetextView);rightlayout.addView(processLayout);//添加左右边leftlayout.addView(rightlayout);mainLayout.addView(leftlayout);}}catch(JSONException e){e.printStackTrace();
电子邮件导出的excel表格文件名乱码是什么原因?
因为经常要用到导出功能,之前因为文件名乱码,所以都用英文或是拼音缩写来代替,今天特意要接觉下这个问题。顺便记录下。望对小白有用。
/**
* 导出结算详情列表
* @return
*/
public void depositLogExport()
{
String title = "押金流水报表";
String excelName = "押金流水报表.xls";
OutputStream os = null;
try
{
int shopId=new Long(getShopLoginer().getShop().getId()).intValue();
if(date==null){
date=new DateBean();
}
int count=service.getCount(shopId, date);
Page<DepositLog> pageResult =new Page<DepositLog>();
if(count>0){
pageResult = service.list(1, count, shopId, date);
}
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
double shopDeposit=getShopLoginer().getShop().getDeposit();
for (DepositLog s : pageResult.getData())
{
Map<String, Object> map = new HashMap<String, Object>();
map.put("id", s.getId());
map.put("depositSn", s.getDepositSn());
map.put("createTime", StringUtils.timestamptoString(s.getCreateTime()));
map.put("type", type[s.getType()]);
map.put("amount", s.getAmount());
map.put("depositRest", s.getDepositRest());
map.put("depositGap", shopDeposit-s.getDepositRest());
map.put("userName", s.getUserName());
map.put("remarks", s.getRemarks());
list.add(map);
}
// 表格表头
String[] header = {"流水号","流水时间","类型","流水金额","押金余额","押金缺口","操作人","备注"};
// 对应Map中的key
String[] key = { "depositSn", "createTime","type",
"amount", "depositRest", "depositGap", "userName", "remarks"};
HSSFWorkbook workbook = null;
HttpServletResponse response = ServletActionContext
.getResponse();
workbook = ExportUtil.workPaperExport(list, header, key,
title, true, null, null, null);
os = response.getOutputStream();
response.setHeader("Content-disposition",
"attachment; filename=" + toUtf8String(excelName));
response.setContentType("application/msexcel;charset=UTF-8");
workbook.write(os);
os.flush();
} catch (Exception e) {
if (logger.isDebugEnabled())
logger.error(e.getMessage(), e);
e.printStackTrace();
} finally {
try {
if (os != null)
os.close();
} catch (IOException e) {
if (logger.isInfoEnabled())
logger.error(e.getMessage(), e);
e.printStackTrace();
}
}
//return null;
}
//文件名乱码处理
public static String toUtf8String(String s){
StringBuffer sb = new StringBuffer();
for (int i=0;i<s.length();i++){
char c = s.charAt(i);
if (c >= 0 && c <= 255){sb.append(c);}
else{
byte[] b;
try { b = Character.toString(c).getBytes("utf-8");}
catch (Exception ex) {
System.out.println(ex);
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0) k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return sb.toString();
}
还没有评论,来说两句吧...