我的java培训日记-2

 
传智播客 java培训 日记 - 2

 

 

1. 换皮肤问题
换肤问题,“内容与表现相分离”。一套内容,多套表现。xml文档提供内容,该怎么样显示,由css或xsl定义。以后尽量采用 DIV + CSS 模式。
一个简单的换皮肤例子:
<HTML>
       <HEAD>
              <META HTTP-EQUIT="Content-Type" content="text/html,charset=GBK" />
              <LINK rel="stylesheet" href="red.css" type="text/css" id="skin" />
              <title>换肤</title>
              <script>
                     function chickSkin(name) {
                            document.getElementById("skin").href=name;
                            return false;
                     }
              </script>
       </HEAD>
       <body>
              <span class="info">aaaaaa</span><br>
              <span class="info">bbbbbb</span><br>
              <span class="info">cccccc</span><br>
              <a href="#" οnclick="return chickSkin('red.css')">红色</a>
              <a href="#" οnclick="return chickSkin('green.css')">绿色</a>
       </body>
</HTML>
Css 代码如下:
red.css
.info {
       color:red;
       txt-decoration="none";
}
green.css
.info {
       color:green;
}
CSS中可以用 txt-decoration="none";去掉超连接的下划线。
小知识:
更改浏览器打开时的编码为GBK可以在<head></head>标签对内加入:<meta http-equiv="Content-Type" content="text/html;charset=GBK">
2. 浏览器与web 服务器互交的过程
讲述了浏览器与web服务器互交的过程,分析程序:
import java.net.*;
import java.io.*;
public class HttpServer
{
       public static void main(String [] args) throws Exception
       {
              ServerSocket serverSocket = new ServerSocket(Integer.parseInt(args[0]));
              while(true)
              {
                     Socket socket = serverSocket.accept();
                     new Thread(new Server(socket)).start();
              }
       }    
}     
class Server implements Runnable
{
                     Socket s = null;
                     public Server(Socket s)
                     {
                            this.s = s;
                     }
                     public void run()
                     {
                            try
                            {
                                   InputStream ips = s.getInputStream();
                                   BufferedReader br = new BufferedReader(new InputStreamReader(ips));
                                   String line = br.readLine();
                                   //GET /a.html HTTP/1.1
                                   String firstLine = line;
                                   while(/*(line == null) || */!"".equals(line))
                                   {
                                          System.out.println(line);
                                          line = br.readLine();
                                   }
                                   String parts [] = firstLine.split(" +");
                                   /*StringTokenizer st = new StringTokenizer(firstLine);
                                   while(st.hasMoreToken())
                                   {
                                          st.nextToken();
                                   }*/
                                   System.out.println(parts[1]);
                                   File f = new File("d://webcontent",parts[1].substring(1));
                                   FileInputStream fis = new FileInputStream(f);
                                   OutputStream ops = s.getOutputStream();
                                   copyStream(fis,ops);
                                   br.close();
                                   ops.close();
                                   fis.close();
                                   s.close();
                            }catch(Exception e){e.printStackTrace();}
                     }
                     void copyStream(InputStream fis,OutputStream ops) throws Exception
                     {
                                   byte [] buf = new byte[1024];
                                   int len = 0;
                                   while((len=fis.read(buf)) != -1)
                                   {
                                          ops.write(buf,0,len);
                                   }
                     }
}     
 
详细: www.itcast.cn

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值