分页: 12/74 第一页 上页 7 8 9 10 11 12 13 14 15 16 下页 最后页 [ 显示模式: 摘要 | 列表 ]
备忘
.test{
width:200px;
height:50px;
border:1px solid red;
padding:10px;
overflow:hidden; /*不显示超过对象宽度的内容*/
text-overflow:ellipsis; /*当对象内文本溢出时显示省略标记(...)*/
white-space:nowrap; /*限制在一行内显示所有文本*/
}
Tags: ,
IIS就是一个灾难,可操作性很差,不悦。。

引用
Request 对象 错误 'ASP 0104 : 80004005'不允许操作 /up/upload.asp,行 20


IIS默认是允许200k的上传,要上传更大,就得修改IIS的配置文件了。

1 打开IIS的属性,允许直接编辑配置数据库,这样不用停止IIS,否则编辑不了配置文件
2 打开 C:\Windows\System32\Inetsrv\metabase.XML
3 修改 ASPMaxRequestEntityAllowed 里的值,比如1024000,10M的大小
4 保存即可
Tags: ,
简单的代码,测试至少是可行
public static void downloadFile(String url, String newPath) {  
  URL myFileUrl = null;  
  try {  
    myFileUrl = new URL(url);  
  } catch (MalformedURLException e) {  
    Log.e("test", "MalformedURLException: "+e.toString() );
  }  
  try {  
    HttpURLConnection conn;
    conn = (HttpURLConnection) myFileUrl.openConnection();
    conn.setDoInput(true);
    conn.connect();  
    InputStream is = conn.getInputStream();  
    FileOutputStream  newfile  =  new  FileOutputStream("/sdcard/tmp.apk");  
    byte[]  buffer  =  new  byte[1444];
    int  byteread  =  0;  
    while  (  (byteread  =  is.read(buffer))  !=  -1)  {  
      newfile.write(buffer,  0,  byteread);  
    }  
    is.close();
  } catch (Exception e) {  
    Log.e("test", "returnNetworkBitMap: "+e.toString() );
  }finally{
  }  
}
Tags:
安装某个apk文件:

String fileName = "/sdcard/tmp.apk";
Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(new File(fileName) ), "application/vnd.android.package-archive");
startActivity(i);


注:如果文件不存在会提示解析出错

卸载某个程序:

Uri packageURI = Uri.parse("package:com.aslibra.test");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);


参考阅读:

Install and Uninstall Android applications with PackageInstaller,包含判断是否开启安装第三方程序的支持

另外还有 Android Intent的几种用法全面总结,必要的时候可以参考啦

Tags:
代码非原创,fix了bug,完善的还是需要再思量:
/**
* 通过拼接的方式构造请求内容,实现参数传输以及文件传输
* @param actionUrl
* @param params
* @param files
* @return
* @throws IOException
*/
public static String post(String actionUrl, Map<String, String> params,
    Map<String, File> files) throws IOException {

  String BOUNDARY = java.util.UUID.randomUUID().toString();
  String PREFIX = "--" , LINEND = "\r\n";
  String MULTIPART_FROM_DATA = "multipart/form-data";
  String CHARSET = "UTF-8";

  URL uri = new URL(actionUrl);
  HttpURLConnection conn = (HttpURLConnection) uri.openConnection();
  conn.setReadTimeout(5 * 1000); // 缓存的最长时间
  conn.setDoInput(true);// 允许输入
  conn.setDoOutput(true);// 允许输出
  conn.setUseCaches(false); // 不允许使用缓存
  conn.setRequestMethod("POST");
  conn.setRequestProperty("connection", "keep-alive");
  conn.setRequestProperty("Charsert", "UTF-8");
  conn.setRequestProperty("Content-Type", MULTIPART_FROM_DATA + ";boundary=" + BOUNDARY);

  // 首先组拼文本类型的参数
  StringBuilder sb = new StringBuilder();
  for (Map.Entry<String, String> entry : params.entrySet()) {
    sb.append(PREFIX);
    sb.append(BOUNDARY);
    sb.append(LINEND);
    sb.append("Content-Disposition: form-data; name=\"" + entry.getKey() + "\"" + LINEND);
    sb.append("Content-Type: text/plain; charset=" + CHARSET+LINEND);
    sb.append("Content-Transfer-Encoding: 8bit" + LINEND);
    sb.append(LINEND);
    sb.append(entry.getValue());
    sb.append(LINEND);
  }

  DataOutputStream outStream = new DataOutputStream(conn.getOutputStream());
  outStream.write(sb.toString().getBytes());
  // 发送文件数据
  if(files!=null){
    int i = 0;
    for (Map.Entry<String, File> file: files.entrySet()) {
      StringBuilder sb1 = new StringBuilder();
      sb1.append(PREFIX);
      sb1.append(BOUNDARY);
      sb1.append(LINEND);
      sb1.append("Content-Disposition: form-data; name=\"file"+(i++)+"\"; filename=\""+file.getKey()+"\""+LINEND);
      sb1.append("Content-Type: application/octet-stream; charset="+CHARSET+LINEND);
      sb1.append(LINEND);
      outStream.write(sb1.toString().getBytes());

      InputStream is = new FileInputStream(file.getValue());
      byte[] buffer = new byte[1024];
      int len = 0;
      while ((len = is.read(buffer)) != -1) {
        outStream.write(buffer, 0, len);
      }

      is.close();
      outStream.write(LINEND.getBytes());
    }
  }
  
  //请求结束标志
  byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINEND).getBytes();
  outStream.write(end_data);
  outStream.flush();

  //得到响应码
  int res = conn.getResponseCode();
  InputStream in = null;
  if (res == 200) {
    in = conn.getInputStream();
    int ch;
    StringBuilder sb2 = new StringBuilder();
    while ((ch = in.read()) != -1) {
      sb2.append((char) ch);
    }
  }
  return in == null ? null : in.toString();
}
Tags: ,
主要是另外增加一个HOST节点即可,便捷的查找方式:

找到以下节点
</Engine>

在前面加上:

<Host name="www.aslibra.com" debug="0" appBase="/home/jsp/www.aslibra.com" unpackWARs="true" autoDeploy="true">
  <Context path="" docBase="."/>      
  <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  prefix="aslibra_access_log."
  suffix=".txt" pattern="common" resolveHosts="false"/>
  <Logger className="org.apache.catalina.logger.FileLogger" directory="logs"  prefix="aslibra_log." suffix=".txt" timestamp="true"/>
</Host>


name 是域名,appBase是根目录
日志选项也可以定义。
Tags: ,
Dnsmasq是一个很实用的小工具,解决局域网的需求看来非常合适,特别是网关和防火墙上。

它可以提供如下几个实用的功能:
1 提供dns服务
2 优先使用本地自定义dns
3 提供dhcp服务

一般情况下,我们可以用bind解决dns的问题,dhcpd解决dhcp的问题,另外,还可以用ypbind解决自定义hostname解析的ip(当然还有用户的功能),它都解决了!很实用吧?这真的很吸引人,况且它一直在更新维护,最新版本是6月份的。

安装过程很简单:

wget http://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.55.tar.gz
tar xfz dnsmasq-2.55.tar.gz
cd dnsmasq-2.55
make
make install
cp dnsmasq.conf.example /etc/dnsmasq.conf


运行起来就可以解决第一个问题:

[root@aslibra dnsmasq-2.55]# dnsmasq
[root@aslibra dnsmasq-2.55]# netstat -nlp|grep dnsmasq
tcp        0      0 0.0.0.0:53                  0.0.0.0:*                   LISTEN      25584/dnsmasq      
tcp        0      0 :::53                       :::*                        LISTEN      25584/dnsmasq      
udp        0      0 0.0.0.0:53                  0.0.0.0:*                               25584/dnsmasq      
udp        0      0 :::53                       :::*                                    25584/dnsmasq      


默认情况下,作为dns服务,第一个问题解决了。

我们尝试解决第二个问题,可以说是dns劫持?没有那么严重,用好了其实很实用。
有如下几个问题比较棘手:

1 局域网有很多机器希望使用一份一样的hosts定义一批名称对应的ip,你需要经常维护这份列表
2 你希望局域网的人访问某个域名时,拦截下来到指定的ip,做缓存节省带宽或者其它用途都可以
3 禁止某个域名的正常解析

这个更改涉及两个文件:
1 /etc/hosts
2 /etc/dnsmasq.conf

我们先在hosts文件里加入两行:

192.168.1.3     server1
192.168.1.2     www.aslibra.com


编辑dnsmasq.conf,找到如下代码:

# Add local-only domains here, queries in these domains are answered
# from /etc/hosts or DHCP only.
local=/localnet/

# Add domains which you want to force to an IP address here.
# The example below send any host in doubleclick.net to a local
# webserver.
#address=/doubleclick.net/127.0.0.1
address=/baidu.com/127.0.0.1


重启dnsmasq即可,下面我们在局域网另外一个机器用dig命令测试一下:
Tags: , ,
分页: 12/74 第一页 上页 7 8 9 10 11 12 13 14 15 16 下页 最后页 [ 显示模式: 摘要 | 列表 ]

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐