BloveSaga

          在希臘帕爾納斯山南坡上,有一個馳名世界的戴爾波伊神托所,在它的入口處的巨石上赫然銹刻著這樣幾個大字: 認識你自己!

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            34 隨筆 :: 12 文章 :: 122 評論 :: 0 Trackbacks

          2006年6月19日 #

          大家可以瀏覽我新的博客 dyin.cn

          posted @ 2007-05-11 16:57 藍色Saga 閱讀(170) | 評論 (0)編輯 收藏

          今天與大家分享的資源如下:
          ==================================================================================
          JSP動態(tài)網(wǎng)頁制作
          PHP動態(tài)網(wǎng)頁制作
          ASP動態(tài)網(wǎng)頁制作
          Perl動態(tài)網(wǎng)頁制作
          winxp優(yōu)化大全
          JSP程序設(shè)計
          以上皆是視頻教程
          如果你需要請你留下email我將會在晚上統(tǒng)一把種子發(fā)送到你的郵箱里,如果需要請抓緊,3天后將不再提供!

          ?

          posted @ 2006-06-21 12:23 藍色Saga 閱讀(345) | 評論 (5)編輯 收藏

          要考慮一個真正意義的全球資源,Web瀏覽器的內(nèi)容對每個接收到的用戶來說都是易讀的,現(xiàn)在大多數(shù)的全球資源的網(wǎng)站都是英文的.當(dāng)然,現(xiàn)在也在發(fā)生變化,有的網(wǎng)站為一些特定的國家定制一些非英文版本,比如,說英文的通過http://www.ibm.com/en/index.html來訪問,說中文的通過http://www.imb.com/cn/index.html來訪問,這些很多都是靜態(tài)的文本.怎么構(gòu)件一個動態(tài)生成的國際化內(nèi)容的網(wǎng)站就不是一個簡單的問題了.

          國際化又稱Il8N,因為英文國家的國家化是Internationalization,它以I開始,以N結(jié)束,共18個字母.本地化又稱L18N,即是Localization.國際化的問題主要包含以下的一些內(nèi)容:
          .日期,時間
          .數(shù)字
          .貨幣
          .其它的一些特殊字符
          也就是說不同的Locale,顯示日期,時間格式是不一樣的.當(dāng)然,不同的語言有自己不同的字符集.

          HTML中的字符實體
          HTML中的字符實體和XML的語言保持一致.它定義了用特定的字符序列顯示單字符的功能,這種字符序列稱為字符實體,它以" &"開頭,以";"結(jié)束.例如: © 表示字符"?";
          看一例子顯示西班牙語的" Hello World":
          <%@page contentType="text/html;charset=ISO-8859-1" %>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          ?? "

          <%
          ?? response.setHeader("Content-Language","es");
          ?? out.println("<html><head><title>En Espa&ntilde;ol</title></head>");
          ?? out.println("<body>");
          ?? out.println("<h3>En espa%ntilde;ol</h3>");
          ?? out.println("&iexcl;Hola Mundo!");
          ?? out.println("</body></html>");
          %>

          運行結(jié)果:

          En espa%ntilde;ol

          ?Hola Mundo!

          在HTML字符實體表示中,&ntilde代表了" ? "字符,使用response.setHeader("Content-Language","es");來設(shè)置HTML顯示時要使用的語言.

          Unicode
          Unicode字符標(biāo)準(zhǔn)是一個字符編碼系統(tǒng),它支持互相轉(zhuǎn)換,處理和顯示現(xiàn)在世界上不同語言的文本.在Java語言中,字符,字符串和標(biāo)始符在內(nèi)部使用16位的Unicode 2.0字符集表示.Unicode使用 " \uxxxx" 來表示一個字符,前256個Unicode字符和ISO-8859-1標(biāo)準(zhǔn)(Latin-1)的前256個字符一致.在Unicode世界中, "? ?? " 用 " \u00f1 " 表示.看怎么用Unicode來編寫西班牙語的Hello World:
          <
          %@page contentType="text/html;charset=ISO-8859-1" %>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          ?? "

          <%
          ?? response.setHeader("Content-Language","es");
          ?? out.println("<html><head><title>En Espa\u00f1ol</title></head>");
          ?? out.println("<body>");
          ?? out.println("<h3>En espa\u00f1ol</h3>");
          ?? out.println("\u00f1Hola Mundo!");
          ?? out.println("</body></html>");
          %>

          支持多國語言的Hello World

          用語選擇語言的頁面:


          語言處理頁面代碼:
          <
          %@page contentType="text/plain;charset=UTF-8"
          import="java.io.*,java.text.*,java.util.*,javax.servlet.jsp.*" %>
          <html>
          ??? <head>
          ??????? <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          ??????? <title>JSP Page</title>
          ??? </head>
          ??? <body>
          <%!
          ?? Locale locale;
          ?? DateFormat format;
          ?? JspWriter writer;
          %>
          <%!
          ?? //英語
          void processEnglish()throws Exception
          {
          ??? locale=new Locale("en","US");
          ??? format=DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG,locale);
          ??? writer.println("in english");
          ??? writer.println("<br>");
          ??? writer.println("HelloWorld");
          ??? writer.println(format.format(new Date()));
          ??? writer.flush();
          }

          ?? //中文
          void processChinese()throws Exception
          {
          ??? locale=new Locale("zh","");
          ??? format=DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG,locale);
          ??? writer.println("in Chinese");
          ??? writer.println("<br>");
          ??? writer.println("\u4f60\u597d\u4e16\u754c");
          ??? writer.println(format.format(new Date()));
          ??? writer.flush();
          }

          ?? //韓國語
          void processKorean()throws Exception
          {
          ??? locale=new Locale("ko","");
          ??? format=DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.LONG,locale);
          ??? writer.println("in Korean");
          ??? writer.println("<br>");
          ??? writer.println("\uc548\ud558\uc138\uacc4");
          ??? writer.println(format.format(new Date()));
          ??? writer.flush();
          }
          //.........................其他的語言省略
          %>
          <%
          ??? //獲得請求的語種
          ???? String language=(String)request.getParameter("language");
          ???? int lan=Integer.parseInt(language);??
          %>
          <%
          ?? writer=out;
          ?? switch(lan)
          ?? {
          ?????? case 1:processEnglish();break;
          ?????? case 2:processChinese();break;
          ?????? case 3:processKorean();break;
          ?????? //case 4:processRussian();break;
          ?????? //case 5:processSpanish();break;
          ????? // case 6:processJapanese();break;
          ?? }
          %>
          ??? </body>
          </html>
          處理的思路很簡單,首先獲得請求的語種,然后根據(jù)不同的語言來做不同的處理.

          posted @ 2006-06-20 14:00 藍色Saga 閱讀(236) | 評論 (0)編輯 收藏

          在JSP開發(fā)中我們常常會碰到以下的一些問題,其實都很有代表性.

          在不同的頁面或者用戶之間共享數(shù)據(jù)

          在JSP中共享數(shù)據(jù),大體上可以分為兩種情況,第一種是在同一個用戶的不同也面之間共享數(shù)據(jù),另一種是在不同用戶之間共享數(shù)據(jù).
          對于同一個用戶的會話,要想在不同的頁面之間共享數(shù)據(jù),可以有以下幾種選擇:
          .把數(shù)據(jù)保存在Session中(最常見的方法)
          .通過Cookie
          .通過隱含表單提交到下一個頁面
          .通過ServletContext對象
          .通過Application對象
          .通過文件系統(tǒng)或者數(shù)據(jù)庫
          要在不同的用戶之間共享數(shù)據(jù),通常的方法是:
          .通過ServletContext對象
          .通過Application對象
          .通過文件系統(tǒng)或者數(shù)據(jù)庫
          可見,對于不同用戶之間共享數(shù)據(jù)的實現(xiàn)方法在同一個用戶的不同也面之間也能實現(xiàn)數(shù)據(jù)共享.
          a.在同一個用戶的不同也面之間共享數(shù)據(jù)
          1.使用session共享數(shù)據(jù)
          用戶在瀏覽網(wǎng)頁時,由于HTTP協(xié)議是一種無狀態(tài)協(xié)議,往往在不同的頁面之間存在數(shù)據(jù)交換的問題,這就需要在這些不同的頁面之間共享數(shù)據(jù).在編程實現(xiàn)中我們??吹降姆椒ㄊ前压蚕頂?shù)據(jù)保存在session中.這些共享數(shù)據(jù)可以是字符串或者與Java的原始數(shù)據(jù)類型相關(guān)的對象,也可以是一個Java對象.
          exampl: 用戶登錄時,如果驗證成功,就把信息保存到一個userSession的類中,在其他的頁面可以讀取這個值.
          userSession.java
          package dory;
          import java.util.Date;
          /**
          ?*
          ?* @author Dory Doo
          ?*/
          public class userSession {
          ??? private boolean isLogin=false;
          ??? private String userId;
          ??? private Date lastLoginTime;
          ??? private int logCount;
          ??? /** Creates a new instance of userSession */
          ??? public userSession() {
          ??? }
          ??? public void setIsLogin(boolean l)
          ??? {
          ??????? this.isLogin=l;
          ??? }
          ??? public void setUserId(String userId)
          ??? {
          ??????? this.userId=userId;
          ??? }
          ??? public void setLastLoginTime(Date l)
          ??? {
          ??????? this.lastLoginTime=l;
          ??? }
          ??? public void setLogCount(int logCount)
          ??? {
          ??????? this.logCount=logCount;
          ??? }
          ??? public boolean isLogin()
          ??? {
          ??????? return this.isLogin;
          ??? }
          ??? public String getUserId()
          ??? {
          ??????? return this.userId;
          ??? }
          ??? public Date getLastLoginTime()
          ??? {
          ??????? return this.lastLoginTime;
          ??? }
          ??? public int getLogCount()
          ??? {
          ??????? return this.logCount;
          ??? }
          }
          當(dāng)然這個就比較簡單的了,要的是整個思路.我們怎么來使用這個類,我們需要一個驗證登陸的頁login.jsp
          <%@page contentType="text/html;charset=gb2312" language="java"
          ?import="java.sql.*,dory.*" errorPage=""%>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          ?? "

          <html>
          ??? <head>
          ??????? <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          ??????? <title>JSP Page</title>
          ??? </head>
          ??? <body>

          ??? <h1>Login Checking Page</h1>
          <%
          ?? String name=request.getParameter("name");
          ?? String password=request.getParameter("password");
          ?? //Connection the Database,loading
          ?? //int logCount=resultSet.getInt("count");
          ?? //java.util.Date lastLoginTime=resultSet.getDate("LastLoginTime");
          ?? //這里簡單設(shè)置logCount和lastLoginTime的值
          ?? UserSession user=new UserSeesion();
          ?? user.setUserId(name);
          ?? user.setIsLogin(true);
          ?? user.setLastLoginTime(new java.util.Date());
          ?? user.setLogCount(10);
          ?? session.setAttribute("userSession",user)
          ?? response.sendRedirect("welcome.jsp");
          %>
          ??? </body>
          </html>
          整個登陸頁面的過程是這樣的:
          (1)獲得用戶的登陸信息
          (2)連接數(shù)據(jù)庫進行權(quán)限驗證
          (3)如果通過驗證,那么讀取用戶的注冊信息
          (4)把用戶的注冊信息保存到一個userSession對象中
          (5)把userSession對象保存到Session內(nèi)建對象中
          (6)把視圖派發(fā)到下一個顯示頁面
          注意:session.setAttribute("userSession",user)把userSession的一個對象設(shè)置到Session中,Session只能保存對象,不能保存原始的數(shù)據(jù)類型,比如:
          session.setAttribute("count",10)
          是非法的語句,如果要把值為10的整數(shù)保存到Session中,需要使用以下的方法:
          session.setAttribute("count",new Integer(10));
          然后在另一個頁面使用
          (Integer)session.getAttribute("count");
          把這個整數(shù)讀出來.
          我們用如下方法在另一個頁面中把userSesseion對象讀取出來:
          <
          %@page contentType="text/html;charset=gb2312" language="java"
          ?import="java.sql.*,dory.*" errorPage=""%>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          ?? "<html>
          ??? <head>
          ??????? <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          ??????? <title>JSP Page</title>
          ??? </head>
          ??? <body>??
          <%
          ?? UserSession user=(UserSession)session.getAttribute("userSession");
          ?? try
          ?? {
          ?????? if(user.isLogin())
          ?????? {
          ?????????? out.print("welcome,your login id is:"+user.getUserId());
          ?????????? out.print("your last login time is:"+user.getLastLoginTime());
          ?????????? out.print("now you are the:"+user.getLogCount()+"times logging this website");
          ?????? }
          ?????? else
          ?????? {
          ?????????? response.sendRedirect("login.html");
          ?????? }
          ?? }
          ?? catch(Exception e)
          ?? {
          ?????? response.sendRedirect("login.html");
          ?? }
          %>
          ??? </body>
          </html>
          可以看出,通過UserSession user=(UserSession)session.getAttribute("userSession");代碼來讀取在前一個頁面中設(shè)置的對象,然后再從這個對象讀取一些相關(guān)值.當(dāng)然我們也可以用JavaBean的形式來讀取.

          2.使用隱含菜單
          這種方式通過隱含菜單的形式把數(shù)據(jù)傳遞到下一個頁面,它有兩個局限性:
          .只能在相鄰的兩個頁面之間傳遞數(shù)據(jù)
          .客戶端可以使用查看網(wǎng)頁源代碼的方式獲得表單中的數(shù)據(jù),安全性不好
          它的實現(xiàn)很簡單:
          <form action="target.jsp">
          <input type="hidden" name="test" value="abc">
          <input type="hidden" name="test2" value="def">
          </form>
          在另外一個頁面中,通過這樣來獲得數(shù)據(jù):
          String test=request.getParameter("test");
          String test2=request.getParameter("test2");

          3.使用Cookie
          和Session不同,Cookie是放在客戶端的,由于客戶考慮到安全應(yīng)素可能會禁用cookie,這樣在使用cookie就會遇到麻煩了.

          b.在不同的用戶之間共享數(shù)據(jù)
          在不同的在不同的用戶之間共享數(shù)據(jù)最常見的方法是使用ServletContext和application對象,通過在一個用戶那里設(shè)置屬性在另一個用戶那里獲得這個屬性.

          1.使用ServletContext
          在JSP頁面中可以通過getServletContext()方法獲得ServletContext對象.在這種情況下不同的用戶通過它來工享數(shù)據(jù),看下面的實現(xiàn)代碼:
          <
          %@page contentType="text/html;charset=gb2312" language="java"
          import="java.sql.*,javax.servlet.*,javax.servlet.http.*,dory.*" errorPage="" %>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          ?? "<%
          ?? request.setCharacterEncoding("gb2312");
          %>
          <html>
          ??? <head>
          ??????? <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          ??????? <title>JSP Page</title>
          ??? </head>
          ??? <body>
          ??? a simple chatting room
          ??? <br><hr><font color="red">
          <%
          ?? String content=(String)getServletContext().getAttribute(new String("chatTopic_1"));
          ?? out.print(content);
          ?? getServletContext().setAttribute("chatTopic_1",content+(String)request.getParameter("content")
          ?? +"<br>");
          %>
          ??? </font>
          ??? <hr>
          ??? <form accept="Servelt Context_chat.jsp">
          ??????? <input type="text" name="content">
          ??????? <input type="submit" value="speak">
          ??? </form>
          ??? </body>
          </html>

          2.application對象
          application對象對應(yīng)于每個web應(yīng)用來說只有一個,它使用和ServletContext差不多.如下:
          <
          %@page contentType="text/html;charset=gb2312" language="java"
          import="java.sql.*,javax.servlet.*,javax.servlet.http.*,dory.*" errorPage="" %>
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          ?? "<%
          ?? request.setCharacterEncoding("gb2312");
          %>
          <html>
          ??? <head>
          ??????? <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
          ??????? <title>JSP Page</title>
          ??? </head>
          ??? <body>
          ??? a simple chatting room
          ??? <br><hr><font color="red">
          <%
          ?? String content=(String)application.getAttribute(new String("chatTopic_1"));
          ?? out.print(content);
          ?? application.setAttribute("chatTopic_1",content+(String)request.getParameter("content")
          ?? +"<br>");
          %>
          ??? </font>
          ??? <hr>
          ??? <form accept="Servelt Context_chat.jsp">
          ??????? <input type="text" name="content">
          ??????? <input type="submit" value="speak">
          ??? </form>
          ??? </body>
          </html>
          可以得到ServletContext和application的實現(xiàn)機制基本上一致.

          posted @ 2006-06-20 13:05 藍色Saga 閱讀(299) | 評論 (0)編輯 收藏

          多學(xué)習(xí)別人才能進步,多交流才能收獲,這里分享給大家一些網(wǎng)絡(luò)資源.

          =====================================================================================
          國內(nèi)外JSP/Java/Servlet技術(shù)著名網(wǎng)站

          http://www-900.ibm.com/developerWorks/cn
          http://java.sun.com
          http://www.jchq.net
          http://jquest.webjump.com/
          http://www.chinaasp.com/ (國內(nèi))
          http://www.cnjsp.com/? (國內(nèi))
          http://www.javaunion.org/ (國內(nèi))
          http://www.jspchina.com/ (國內(nèi))


          國內(nèi)外介紹JSP/Servlet應(yīng)用程序服務(wù)器的網(wǎng)站

          ?http://www.allaire.com/
          ?http://jakarta.apache.org/
          ?http://java.apache.org/
          ?http://www.atg.com/
          ?http://www.bea.com/
          ?http://www.beasys.com/
          ?
          http://www.bluestone.com/
          ?http://caucho.com/
          ?http://easythings.iwarp.com/
          ?http://www.fefionsoftware.com
          ?
          http://www.gemstone.com/
          ?http://www.software.ibm.com/
          ?
          http://www.inprise.com/
          ?http://sun.com/software/
          ?http://www.tagtraum.com/
          ?http://www.enhydra.com/
          ?http://www.mortbay.com/
          ?http://www.novocode.com/
          ?http://www.oracle.com/
          ?http://www.orionserver.com/
          ?http://www.paralogic.com/
          ?http://www.pramati.com/
          ?http://www.secant.com/
          ?http://www.servertec.com/
          ?http://www.silverstream.com/
          ?http://www.siteforum.com/
          ?http://www.unify.com/
          ?http://www.vqsoft.com/
          ?http://www.w3.org/

          國內(nèi)外介紹 JSP/Java/Servlet開發(fā)工具的網(wǎng)站

          ?http://www.adobe.com/
          ?http://www.bea.com/
          ?http://www.software.ibm.com/
          ?http://www.inprise.com/
          ?http://www.macromedia.com/
          ?http://www.netbeans.org/
          ?http://www.netobjects.com/
          ?http://www.oracle.com/
          ?http://www.sun.com/
          ?
          http://www.eclipse.com/

          FAQ網(wǎng)站

          ?http://www.jguru.com/
          ?http://java.sun.com/products/jsp/faq.html
          ?http://www.esperanto.org.nz/
          ?
          http://www.jchq.net/

          繁體資源

          http://www.javaworld.com.tw/jute或http://www.jsptw.com/jute
          http://www.jsp.mlc.edu.tw
          posted @ 2006-06-19 14:49 藍色Saga 閱讀(305) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 孝感市| 元江| 佳木斯市| 天柱县| 阳东县| 鄂托克旗| 阳江市| 竹山县| 云阳县| 高台县| 府谷县| 民乐县| 新营市| 图木舒克市| 江山市| 滦平县| 沁水县| 东乡族自治县| 准格尔旗| 综艺| 龙川县| 交城县| 蓬安县| 武陟县| 阿图什市| 天峨县| 故城县| 高密市| 临洮县| 方山县| 佛山市| 比如县| 阳曲县| 双城市| 册亨县| 遵义县| 汉中市| 长顺县| 略阳县| 大竹县| 涟源市|