Archive for the '旧的回忆' Category

Log4j 简易使用指南

星期一, 十二月 22nd, 2003

依据log4j的mannual中在servlet应用的一个例子


Log4jInit
package com.foo;


import org.apache.log4j.PropertyConfigurator;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.IOException;


public class Log4jInit extends HttpServlet {


  public
  void init() {
    String prefix =  getServletContext().getRealPath(“/”);
    String file = getInitParameter(“log4j-init-file”);
    // if the log4j-init-file is not set, then no point in trying
    if(file != null) {
      PropertyConfigurator.configure(prefix+file);
    }
  }


  public
  void doGet(HttpServletRequest req, HttpServletResponse res) {
  }
}


web.xml
  <servlet>
    <servlet-name>log4j-init</servlet-name>
    <servlet-class>com.foo.Log4jInit</servlet-class>


    <init-param>
      <param-name>log4j-init-file</param-name>
      <param-value>WEB-INF/classes/log4j.lcf</param-value>
    </init-param>


    <load-on-startup>1</load-on-startup>
  </servlet>


log4j.lcf
log4j.rootLogger=debug, stdout, R


log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout


# Pattern to output the caller’s file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) – %m%n
#R 输出到文件
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=d:/log4j.log


log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1


log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%p] %d{yyyy-MM-dd HH:mm:ss} %x %t %c – %m%n


In any class u can use like this
   Logger log = Logger.getLogger(this.getClass().getName());
   log.error(se);


When shut down
LogManager.shutdown();

DHTML高级使用: Event Hook

星期日, 十二月 21st, 2003

代码来源: 微软出版社出版<Inside DHTML>


<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
 <head>
  <title>Event Hook</title>
  <meta name=”GENERATOR” content=”Microsoft Visual Studio.NET 7.0″>
  <meta name=”vs_targetSchema” content=”http://schemas.microsoft.com/intellisense/ie5″>
  <style>
   .out {text-decoration: none}
   .over {text-decoration: underline}
  </style>
  <script>
   function hookupEvents(){
    var bindings = document.all.tags(“BINDEVENT”);
    for(var intLoop = 0; intLoop < bindings.length; intLoop++){
     var bind = bindings[intLoop];
     if(( null != bind.getAttribute(“event”)) &&
        (null != bind.getAttribute(“action”))){
       
        var bEvent = bind.getAttribute(“event”);
        var bAction = new Function( “return ” +
                    bind.getAttribute(“action”) +
                    ”(arguments[0]);”);
        var bCondition = ( null == bind.getAttribute(“condition”)) ?
               null:
               new Function( “return “+
                      bind.getAttribute(“condition”) +
                      ”(arguments[0]);” );
       var bTree = ( “walk” == bind.getAttribute(“tree”));
       var bSrc = bind.getAttribute(“for”);
       //alert(bCondition);
       register( bEvent, bAction, bCondition, bTree, bSrc);
     }
    }
   }
   
   function register(eventName, action){
    var eventSrc = ( null != arguments[4]) ?
            document.all[arguments[4]] :
            document;
    if( null == eventSrc.manager)
     eventSrc.manager = new Object;
    if( null == eventSrc.manager[eventName] ) {
     eventSrc.manager[eventName] = new Object;
     eventSrc.manager[eventName].length = 0;
     setupHandler(eventName, eventSrc);
    }
    
    var ct = eventSrc.manager[eventName].length++;
//    alert(eventSrc.manager[eventName].length);
    eventSrc.manager[eventName][ct] = new Object;
    eventSrc.manager[eventName][ct].doAction = action;
    eventSrc.manager[eventName][ct].condition =
     (null != arguments[2]) ? arguments[2] : alwaysTrue;
    eventSrc.manager[eventName][ct].doTree =
     (null != arguments[3]) ? arguments[3] : false;    
   }
   
   function setupHandler(eventName, eventSrc){
    eventSrc[eventName] = new Function( “runHandler( ‘” + eventName + “‘, this);”);
//    alert(eventSrc[eventName]);
   }
   
   function alwaysTrue(){
    return true;
   }
   
   function runHandler(eventName, eventSrc){
    var src = event.srcElement;
    for(var intLoop = 0; intLoop < eventSrc.manager[eventName].length; intLoop++){
//     alert(eventName+”:”+intLoop+”:”+eventSrc.manager[eventName][intLoop].condition);
     if( eventSrc.manager[eventName][intLoop].condition(src) )
      eventSrc.manager[eventName][intLoop].doAction(src);
    }
    
    src = src.parentElement;
    
    var top = ( this.tagName == null) ? “HTML” : this.tagName;
    while( top != src.tagName){
     for( var intLoop=0; intLoop < eventSrc.manager[eventName].length; intLoop++)
      if( eventSrc.manager[eventName][intLoop].condition(src) &&
       eventSrc.manager[eventName][intLoop].doTree)
       eventSrc.manager[eventName][intLoop].doAction(src);
       
     src = src.parentElement;
    }
   }
   
   //////////////////////////demostration****************************************************************************************
   
   function swapEffects (src){
    if( null != src.getAttribute(“effect”)){
     var tempClass = src.className;
     src.className = src.getAttribute(“effect”);
     src.setAttribute(“effect”, tempClass);
    }
   }
   
   function checkEffect(src){
    return (src.getAttribute(“effect”) !=null);
   }
   
   function swapText(src){
    src.innerText = “mouse over”;
   }
   window.onload = hookupEvents;
  </script>
 </head>
 <body >something not important
 <BINDEVENT event=”onmouseover” action=”swapEffects” condition=”checkEffect” tree=”walk” for=”myLink”></BINDEVENT>
<!–<BINDEVENT event=”onmouseover” action=”swapText” tree=”walk” for=”myLink”></BINDEVENT>–>
 <BINDEVENT event=”onmouseout” action=”swapEffects” condition=”checkEffect” tree=”walk” for=”myLink”></BINDEVENT>


 <font effect=over tree=”walk”>aaa <a href=# id=myLink effect=”over” class=”out”>mouse over <b>a</b>nd out effect</a></font>
 </body>
</html>


show effects of the code above

Sign a JAR

星期日, 十二月 21st, 2003

在applet中使用超过沙箱权限时可以通过对applet签名弹出用户确认窗口打开限制:


> keytool -genkey -alias mars -keypass pwdformars -keystore marsstore
> jar cvf Signed.jar *.class
> jarsigner -keystore marsstore -signedjar mars.jar Signed.jar mars


然后在applet中加入


<PARAM NAME = ARCHIVE VALUE = “mars.jar” >


详细参考:
http://www.mhdn.net/p/2002-11-06/6240.html
http://java.sun.com/security/signExample12/

web.xml quick reference

星期六, 十二月 20th, 2003

dtd类型
Servlet2.3
<!DOCTYPE web-app
    PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN”
    “http://java.sun.com/dtd/web-app_2_3.dtd”>
or
Servlet2.4
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
    xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd”
    version=”2.4″>
</web-app>


顶级元素
<webapp></webapp>


servlet元素
基本
<servlet>
  <servlet-name>你给servlet起的名字</servlet-name>
  <servlet-class>对照在WEB-INF/classes中的类名称</servlet-class>
 </servlet>
DTD定义
<!ELEMENT servlet (icon?, servlet-name, display-name?, description?, (servlet-class | jsp-file), init-param*, load-on-startup?, run-as?, security-role-ref*)>
init-param:初始化参数,servlet可以从这里得到初始参数值。(String initial = getInitParameter(“initial”);    )
load-on-startup:webapplication启动即装载。


servlet-mapping元素
 <servlet-mapping>
  <servlet-name>servlet名称</servlet-name>
  <url-pattern>映射url, i.e. /* or /hello.html</url-pattern>
 </servlet-mapping>


设置Session
 <session-config>
  <session-timeout>
            1 <!– minutes –>
  </session-timeout>
 </session-config>


HTTP认证
<web-app>
    <servlet>
        <servlet-name>
            secret
        </servlet-name>
        <servlet-class>
            SalaryServer
        </servlet-class>
    </servlet>


    <security-constraint>
        <web-resource-collection>
            <web-resource-name>
                SecretProtection
            </web-resource-name>
            <url-pattern>
                /servlet/*
            </url-pattern>
            <http-method>
                GET
            </http-method>
            <http-method>
                POST
            </http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>
                engineer
            </role-name>
        </auth-constraint>
    </security-constraint>


    <login-config>
        <auth-method>
            BASIC       <!– BASIC, DIGEST, FORM, CLIENT-CERT –>
        </auth-method>                                              
        <realm-name>                                                
            Default     <!– optional, only useful for BASIC –>    
        </realm-name>                                               
    </login-config>                                                 


    <security-role>
        <role-name>
            engineer
        </role-name>
    </security-role>
</web-app>

编程土鳖

星期三, 十二月 17th, 2003

    到这个公司4个月了,不知道还能待多久,我已经厌倦了最底层的工作,至少物质生活的刺激让我觉得不能再这样,但我至少希望在这里能看到一些我想看到的东西,见识一些未曾接触的东西再考虑下一步。但现在还没有。我理解了程序员就是驴这句话,尤其是在这种有一点规模的公司,分工更细的公司,发挥自己的想象力不如快速机械的完成一件流程工作,不过至今我也还没做过什么具体工作,不知道为什么我总是扮演闲人的角色,难道是态度不够积极?不过我确实不想碰那些无聊的东西。


    眼高手低就是我,想到的永远比能做到的多,有好几次想开始做个什么东西,但总是在不能解决最终的问题、困扰我的问题而在一次又一次思考后抛弃掉。


    烦恼,感觉很烦,很久没有体验过升级的快感了,象是困在游戏迷宫中一样,不知道往哪个方向去才是正途。其实这个问题一直存在,以前有个不清晰、高远的目标,那时会为那目标而兴奋,当淡忘掉之后,才发现自己没有一个具体的方向,不为名不为利的目标实在无法为之去努力实践。


    除了编程,我对其他的东西现在似乎都知道的很少了,而对于编程,想知道的又太多,网络、3D和多媒体、数据库、无线设备每一个都是要积数年之功才能有所成就的领域,真是很羡慕有天龙八部里无涯子那种精通百艺的人。虽然编程有一通百通的说法,但有很多东西是需要行业知识去解决的,现在想来,要靠自己一人之力完成任何一个像样的作品都几乎是不可能的。


    如果程序员可以分为若干级别,我想我还属于土鳖一类,但是经过十数次小小的升级之后我觉得,也许一次大的蜕变要来了,感觉象是体内不成形的力量逐渐要聚集起来,却不知道如何释放出来,也许只是一种感觉,有时高亢有时压抑,也许还要3、4个月时间可以度过这一关。


    我只希望以后我的每一步都能得到相当付出的回报,我希望自己能努力的实现我的每个目标,能再一两年内再把对编程的感觉提高到一个新的层次,我不想再当个土鳖,或许以前也是一段美好的时光,但是现在需要改变,所有的东西。

栏目说明

星期二, 十二月 16th, 2003

栏目介绍

星期二, 十二月 16th, 2003

栏目介绍

星期二, 十二月 16th, 2003

栏目介绍

星期二, 十二月 16th, 2003

栏目介绍

星期二, 十二月 16th, 2003