fhdking
发贴: 28
积分: 0
|
于 2007-10-21 14:53
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="#" onclick="return chickSkin('red.css')">红色</a> <a href="#" onclick="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; 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); } } }
|