http://zeusami.iteye.com/blog/1172864
http://www.cnblogs.com/winkey4986/p/5478332.html
http://zheyiw.iteye.com/blog/1571222
http://blog.csdn.net/jaikydota163/article/details/51458880
http://www.cnblogs.com/boy1025/p/4551593.html
http://www.cnblogs.com/maocs/p/4256302.html
http://josh-persistence.iteye.com/blog/1922311
http://www.cnblogs.com/adventurer/p/5493979.html
http://blog.csdn.net/cuiyaoqiang/article/details/51422460
https://my.oschina.net/Tsher2015/blog/494275
http://www.jb51.net/article/53589.htm
http://blog.csdn.net/taijianyu/article/details/44672035
http://www.cnblogs.com/boy1025/p/4551593.html
http://www.cnblogs.com/yisheng163/p/4524808.html
http://blog.csdn.net/laodagewo/article/details/46279711
http://www.cnblogs.com/X-knight/p/5406362.html
http://www.cnblogs.com/X-knight/p/5406362.html http://www.2cto.com/kf/201511/449957.html http://blog.csdn.net/xingfeng2010/article/details/21408907
https://segmentfault.com/q/1010000000375424 http://www.2cto.com/kf/201104/88264.html https://segmentfault.com/q/1010000000181188
http://www.360doc.com/content/14/0612/14/16688557_385991322.shtml http://blog.csdn.net/gqqzxc/article/details/52798791
集群:
http://blog.csdn.net/hll814/article/details/50935765
http://blog.csdn.net/hll814/article/details/50936063
http://blog.csdn.net/zyk906705975/article/details/8471475
https://zhidao.baidu.com/question/415912602.html
http://blog.csdn.net/henulwj/article/details/8961876
http://blog.csdn.net/u013076997/article/details/52299833
http://blog.csdn.net/u013076997/article/details/52299833
https://zhidao.baidu.com/question/415912602.html
http://blog.csdn.net/zyk906705975/article/details/8471475
在自己的电脑上配置 多个tomcat: 代码:
第一个服务器
CATALINA_HOME
C:\Users\Administrator\Desktop\apache-tomcat-7.0.72
%CATALINA_HOME%\bin
======================================
CATALINA_HOME2
E:\apache-tomcat-7.0.72
;%CATALINA_HOME2%\bin
修改新的tomcat中的startup.bat,把其中all的CATALINA_HOME改为CATALINA_HOME2。
修改新的tomcat中的catalina.bat,把其中all的CATALINA_HOME改为CATALINA_HOME2。
修改conf/server.xml文件:
<Server port="8006" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Connector port="8082" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />
http://blog.csdn.net/jbgtwang/article/details/4479115 apache 好的。好的好的
http://www.jb51.net/os/windows/170997.html 查看端口 被占用端口
netstat -ano|findstr 80
http://jingyan.baidu.com/article/3aed632e24d3c5701180916d.html 端口与进程的关系操作
http://www.2cto.com/os/201111/111269.html apache 80端口被占用解决
http://blog.csdn.net/chaosbead/article/details/20496853
http://blog.csdn.net/jiaotuwoaini/article/details/51455829
https://zhidao.baidu.com/question/1434586832877701179.html
http://www.xuephp.com/main/detail.php?cid=40711、
http://www.xuephp.com/main/detail.php?cid=40711
http://www.cnblogs.com/ericsun/archive/2011/07/13/2105500.html
http://blog.sina.com.cn/s/blog_69b9434b0101alsd.html
http://jingyan.baidu.com/article/0eb457e50fabcc03f0a9056d.html
http://blog.csdn.net/zhanshenyn/article/details/6976861
http://www.360doc.com/content/07/0316/10/7147_399333.shtml
http://blog.csdn.net/lifuxiangcaohui/article/details/8558532
http://michaelh0226.iteye.com/blog/1175561
http://www.sendong.com/news1663.html
http://michaelh0226.iteye.com/blog/1175561
================================================
第9章 :
网络通信:
private void sendRequestWithOkHttp(){
new Thread( new Runnable() {
public void run(){
try{
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("后面告诉你这个地址").build();
Response response = client.newCall(request).execute();
String responseData = response.body().string();
//showResponse( responseData );
}catch( Exception e) {
e.printStackTrace();
}
}
}).start();
}
-------------------
第10章 : 服务
更新应用程序中的UI,必须在主线程中执行,在子线程中执行会出错。
验证案例:新建 AndroidThreadTest 项目,修改 activity_main.xml文档:
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="hello world ! "
android:textSize="20sp" />
<Button
android:id ="@+id/change_text" //定义算术的标识符,+去掉表示引用
android:layout_width="wrap_parent"
android:layout_height="wrap_content"
android:text="Change Text"
/>
接着修改 MainActivity 中的代码:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView text;
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState ) ;
setContentView( R.layout.activity_main ) ; //加载了新的布局
text = ( TextView ) findViewById( R.id.text );
Button change_text = ( Button ) findViewById( R.id.change_text );
change_text .setOnClickListener( new View.OnClickListener( ) {
}
public void onClick( View v ){
switch( v.getId()) {
case R.id.change_text:
new Thread( new Runnable()
{ public void run(){ text.setText("Nice to meet you"); }
}
}).start(); break;
default: break;
}
}
}
上述程序崩溃了。
如果 我们要创建子线程,子线程执行完任务后把结果 更新UI控件,该如何实现呢?
可以 引入 异步消息处理机制。
接着修改 MainActivity 中的代码:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
public static final int UPDATE_TEXT =1 ;
private TextView text;
private Handler handler = new Handler() {
public void handleMessage( Message msg ) {
switch( msg.what ) {
case UPDATE_TEXT : text.setText("Nice to meet you"); break;
default: break;
}
}
};
public void onClick( View v ){
switch( v.getId()) {
case R.id.change_text:
new Thread( new Runnable()
{ public void run(){
Message message = new Message();
message.what = UPDATE_TEXT;
handler.sendMessage(message);
}
}
}).start(); break;
default: break;
}
}
}
开始解释:
Message :用于在不同线程之间交换少量的信息数据(叫做消息),
Handler : 主要用于发送(sendMessage() )和处理消息(handleMessage() )的。
MessageQueue : 是消息队列,用于存放来自于 Handler发送来的消息。
每个线程中只有一个这个对象。
Looper: 是每个线程中的MessageQueue的管家,调用Looper的loop()后,就会进入到无线
的循环当中,去取出MessageQueue 中的消息。
服务:
ServiceTest项目,右击com.example.servicetest new Service service: 命名:MyService
勾选那2个属性 。
public class MyService extends Service {
public MyService(){
}
public IBinder onBind( Intent intent ){ throw new UnsupportedOperationException
("Not yet implemented");}
public void onCreate() { super.onCreate() ; }//方法在服务创建的时候调用
public int onStartCommand( Intent intent , int flags , int startId ) { //方法在服务启动的时候调用
return super.onStartCommand(intent ,flags ,startId ); }
public void onDestory() { super.onDestory() ; }
}
此时,服务已经在 在 AndroidManifest.xml 中 注册了。
代码:
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"
>
</service>
学习 启动 和停止服务:
首先修改 activity_main.xml 代码:
修改 activity_main.xml文档:
<Button
android:id ="@+id/start_service" //定义算术的标识符,+去掉表示引用
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Service"
/>
<Button
android:id ="@+id/stop_service" //定义算术的标识符,+去掉表示引用
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Service"
/>
接着修改 MainActivity 中的代码:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState ) ;
setContentView( R.layout.activity_main ) ; //加载了新的布局
Button startService = ( Button ) findViewById( R.id.start_service );
Button stopService = ( Button ) findViewById( R.id.stop_service );
startService.setOnClickListener( this) ;
stopService.setOnClickListener( this) ;
public void onClick( View v ){
switch( v.getId()) {
case R.id.start_service:
Intent startIntent = new Intent( this , MyService.class );
startService( startIntent ); // 启动服务
break;
case R.id.stop_service:
Intent stopIntent = new Intent( this , MyService.class );
stopService( stopIntent ); // 启动服务
break;
default: break;
}
}
}
// 在服务自身中 添加 stopSelf() ,服务会自动停止。
验证 服务启动和停止:
public class MyService extends Service {
public MyService(){
}
public IBinder onBind( Intent intent ){ throw new UnsupportedOperationException
("Not yet implemented");}
public void onCreate() { super.onCreate() ;
Log.d( "MyService" , "onCreate executed" );
}//方法在首次(仅仅开始一次)服务创建的时候调用
public int onStartCommand( Intent intent , int flags , int startId ) {
//方法在每次服务启动的时候调用
Log.d( "MyService" , "onStartCommand executed" );
return super.onStartCommand(intent ,flags ,startId ); }
public void onDestory() {
super.onDestory() ;
Log.d( "MyService" , "onDestory executed" );
}
}
活动指挥 服务执行任务(下载):onBind() .
public class MyService extends Service {
private DownloadBinder mBinder = new DownloadBinder();
class DownloadBinder extends Binder{
public void startDownload() { Log.d( "MyService" , "startDownload executed" ); }
}
public int getProgress() {
Log.d( "MyService" , "getProgress executed" ); return 0 ; }
}
public MyService(){
}
// public IBinder onBind( Intent intent ){ throw new UnsupportedOperationException
// ("Not yet implemented");}
public IBinder onBind( Intent intent ){ return mBinder; }
public void onCreate() { super.onCreate() ;
Log.d( "MyService" , "onCreate executed" );
}//方法在首次(仅仅开始一次)服务创建的时候调用
public int onStartCommand( Intent intent , int flags , int startId ) {
//方法在每次服务启动的时候调用
Log.d( "MyService" , "onStartCommand executed" );
return super.onStartCommand(intent ,flags ,startId ); }
public void onDestory() {
super.onDestory() ;
Log.d( "MyService" , "onDestory executed" );
}
}
解析JSON格式数据:
get_data.json
[{"id":"5","version":"5.5","name":"Clash of class"},
{"id":"6","version":"7.0","name":"Boom Beach"},
{"id":"7","version":"3.5","name":"Clash Royable"}]
通过http访问以上数据。
{"content":"报名处","datatime":"2017-3-1","id":1,"sender":"教务处 ","theme":"大学4,6级考试"}
给王的测试数据 :
[{"content":"报名点闽科教务处,付款60元","datatime":"2017-3-1","id":1,"sender":"教务处
","theme":"大学4,6级考试"},{"content":"报名点闽科教务处,付款100元","datatime":"2017-3-
2","id":2,"sender":"教务处 ","theme":"大学英语专8级考试"},{"content":"报名点闽科教务处,付
款120元","datatime":"2017-3-3","id":3,"sender":"教务处 ","theme":"期末重修考试"}]
使用JSONObject : 解析上面的数据:
接着修改 MainActivity 中的代码:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
。。。。。
private void sendRequestWithOkHttp() {
new Thread( new Runnable() {
public void run(){
try{
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder().url
("http://10.0.2.2/get_data.json").build();
Response response = client.newCall( request).execute() ;//获取数据
String responseData = response.body().string();
parseJSONWithJSONObject(responseData); // 解析数据
}catch( Exception e ) {
e.printStackTrace();
}
)
}).start();
}
..................................
private void parseJSONWithJSONObject( String jsonData ) {
try{
JSONArray jsonArray = new JSONArray(jsonData);
for( int i=0; i<jsonArray.length();i++)
{
JSONObject jsonObject = jsonArray.getJSONObject(i);
String id = jsonObject.getString("id");
String name = jsonObject.getString("name");
String version = jsonObject.getString("version");
Log.d( "MainActivity" , "id is "+ id );
}
}catch( Exception e ) {
e.printStackTrace();
}
}
}
// 调用GSON jar工具包封装好的toJson方法,可直接生成JSON字符串
Gson gson = new Gson();
String json = gson.toJson(nt);
// 输出到界面
System.out.println(json);
resp.setContentType("text/plain");
resp.setCharacterEncoding("gb2312");
PrintWriter out = new PrintWriter(resp.getOutputStream());
out.print(json);
out.flush();
// 更多Json转换使用请看JsonTest类
也可以使用GSON : 解析上面的数据: 这里先暂时略写了。
http://www.cnblogs.com/free-dom/p/5801866.html 此网址可以对对象转换成JSON格式的数
据
public class Student {
//姓名
private String name;
//年龄
private String age;
//住址
private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + ", address="
+ address + "]";
}
}
---------
public static void convertObject() {
Student stu=new Student();
stu.setName("JSON");
stu.setAge("23");
stu.setAddress("北京市西城区");
//1、使用JSONObject
JSONObject json = JSONObject.fromObject(stu);
//2、使用JSONArray
JSONArray array=JSONArray.fromObject(stu);
String strJson=json.toString();
String strArray=array.toString();
System.out.println("strJson:"+strJson);
System.out.println("strArray:"+strArray);
}
我定义了一个Student的实体类,然后分别使用了JSONObject和JSONArray两种方式转化为
JSON字符串,下面看打印的结果,
strJson:{"address":"北京市西城区","age":"23","name":"JSON"}
strArray:[{"address":"北京市西城区","age":"23","name":"JSON"}]从结果中可以看出两种方法都可
以把java对象转化为JSON字符串,只是转化后的结构不同。