Bo's profile外热忱棵的家PhotosBlogListsMore Tools Help

Blog


    22/07/2009

    正则表达式

    正则表达式
    Regular Expressions patterns
     
    相关链接
    这个是个英文版的,看得不大懂,下面这个链接有点像参考手册,写得好像也挺浅显易懂的。
     
    如果你不觉得正则表达式很难读写的话,要么你是一个天才,要么,你不是地球人。正则表达式的语法很令人头疼,即使对经常使用它的人来说也是如此。
     
     

    js 日期比较

    哎,发现自己什么都不会,先实行拿来主义再说……
     
    项目中输入框日期格式不统一,两个日期比较不能按一个日期格式比较。这个js方法虽然繁琐写,但是包括的日期格式比较多,能够适应大多数日期比较。

    Js代码 复制代码
    1. /**  
    2.  * 判断是不是一个正确的时间 yyyy-MM-dd  
    3.  * @param {String} str  
    4.  * @return {Date}  
    5.  */  
    6. Date.isSimpleDate = function(str){   
    7.     var   reg   =   /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/;   
    8.     var r = str.match(reg);   
    9.     if(r==null)return   null;   
    10.     var   d=   new   Date(r[1], r[3]-1,r[4]);   
    11.     var   newStr=d.getFullYear() + "-";   
    12.     newStr+=(((d.getMonth()+1)<10&&r[3].length>1)?('0'+(d.getMonth()+1)):(d.getMonth()+1)) + "-" ;   
    13.     newStr+=(((d.getDate())<10 && r[4].length>1)?('0'+d.getDate()):d.getDate());   
    14.     if(newStr==str){   
    15.         return d;   
    16.     }else{   
    17.         return null;   
    18.     }   
    19. }   
    20. /**  
    21.  * 判断是不是一个正确的时间类型 yyyy-MM-dd hh  
    22.  * @param {Object} str  
    23.  */  
    24. Date.isDateHH = function(str){   
    25.     var   reg   =   /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2})$/;   
    26.     var r = str.match(reg);   
    27.     if(r==null)return   null;   
    28.     var   d=   new   Date(r[1], r[3]-1,r[4],r[5]);   
    29.     var   newStr=d.getFullYear() + "-";   
    30.     newStr+=(((d.getMonth()+1)<10&&r[3].length>1)?('0'+(d.getMonth()+1)):(d.getMonth()+1)) + "-" ;   
    31.     newStr+=(((d.getDate())<10 && r[4].length>1)?('0'+d.getDate()):d.getDate()) + " ";   
    32.     newStr+=((d.getHours()<10&&r[5].length>1)?('0'+d.getHours()):d.getHours());   
    33.     if(newStr==str){   
    34.         return d;   
    35.     }else{   
    36.         return null;   
    37.     }   
    38. }   
    39. /**  
    40.  * 判断是不是一个正确的时间类型 yyyy-MM-dd hh:mm  
    41.  * @param {String} str  
    42.  */  
    43. Date.isDateHHMM = function(str){   
    44.     var   reg   =   /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2})$/;   
    45.     var   r   =   str.match(reg);   
    46.     if(r==null)return   null;   
    47.     var   d=   new   Date(r[1], r[3]-1,r[4],r[5],r[6]);   
    48.     var   newStr=d.getFullYear() + "-";   
    49.     newStr+=(((d.getMonth()+1)<10&&r[3].length>1)?('0'+(d.getMonth()+1)):(d.getMonth()+1)) + "-" ;   
    50.     newStr+=(((d.getDate())<10 && r[4].length>1)?('0'+d.getDate()):d.getDate()) + " ";   
    51.     newStr += ((d.getHours()<10&&r[5].length>1)?('0'+d.getHours()):d.getHours())+":";   
    52.     newStr += ((d.getMinutes()<10&&r[6].length>1)?('0'+d.getMinutes()):d.getMinutes());   
    53.     if(newStr==str){   
    54.         return d;   
    55.     }else{   
    56.         return null;   
    57.     }   
    58. }   
    59. /**  
    60.  * 判断是不是一个正确的时间类型 yyyy-MM-dd hh:mm:ss  
    61.  * @param {String} str  
    62.  */  
    63. Date.isDateHHMMSS = function(str){   
    64.     var   reg   =   /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;   
    65.     var   r   =   str.match(reg);   
    66.     if(r==null)return   null;   
    67.     var   d=   new   Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);   
    68.     var   newStr=d.getFullYear() + "-";   
    69.     newStr+=(((d.getMonth()+1)<10&&r[3].length>1)?('0'+(d.getMonth()+1)):(d.getMonth()+1)) + "-" ;   
    70.     newStr+=(((d.getDate())<10 && r[4].length>1)?('0'+d.getDate()):d.getDate()) + " ";   
    71.     newStr += (((d.getHours()<10&&r[5].length>1)?('0'+d.getHours()):d.getHours()))+":";   
    72.     newStr += (((d.getMinutes()<10&&r[6].length>1)?('0'+d.getMinutes()):d.getMinutes())) + ":";   
    73.     newStr += ((d.getSeconds()<10&&r[7].length>1)?('0'+d.getSeconds()):d.getSeconds());   
    74.     if(newStr==str){   
    75.         return d;   
    76.     }else{   
    77.         return null;   
    78.     }   
    79. }   
    80. /***  
    81.  * 判断是日期1是不是在日期2后面  
    82.  * @param {Date/String} d1  
    83.  * @param {Date/String} d2  
    84.  * @return {Boolean} true 小于日期2  
    85.  */  
    86. Date.before = function(d1,d2){   
    87.     if((typeof d1 == 'object' && d1.constructor == Date) && (typeof d2 == 'object' && d2.constructor == Date)){   
    88.         if(d1<=d2){   
    89.             return true;   
    90.         }else{   
    91.             return false;   
    92.         }   
    93.     }else if((typeof d1 == 'string' && d1.constructor == String) && (typeof d2 == 'string' && d2.constructor == String)){   
    94.   
    95.         var date1 = Date.isSimpleDate(d1)!=null?Date.isSimpleDate(d1):Date.isDateHH(d1);   
    96.         date1 = date1!=null?date1:Date.isDateHHMM(d1);   
    97.         date1 = date1!=null?date1:Date.isDateHHMMSS(d1);   
    98.         var date2 = Date.isSimpleDate(d2)!=null?Date.isSimpleDate(d2):Date.isDateHH(d2);   
    99.         date2 = date2!=null?date2:Date.isDateHHMM(d2)   
    100.         date2 = date2!=null?date2:Date.isDateHHMMSS(d2);   
    101.         if(date1==null||date2==null){   
    102.             alert("日期格式不正确!");   
    103.             return false;   
    104.         }   
    105.         if(date1<=date2){   
    106.             return true;   
    107.         }else{   
    108.             return false;   
    109.         }   
    110.     }else if((typeof d1 == 'string' && d1.constructor == String) && (typeof d2 == 'object' && d2.constructor == Date)){   
    111.   
    112.         var date1 = Date.isSimpleDate(d1)!=null?Date.isSimpleDate(d1):Date.isDateHH(d1);   
    113.         date1 = date1!=null?date1:Date.isDateHHMM(d1);   
    114.         date1 = date1!=null?date1:Date.isDateHHMMSS(d1);   
    115.         if(date1==null||d2==null){   
    116.             alert("日期格式不正确!");   
    117.             return false;   
    118.         }   
    119.         if(date1<=d2){   
    120.             return true;   
    121.         }else{   
    122.             return false;   
    123.         }   
    124.     }else if((typeof d1 == 'object' && d1.constructor == Date) && (typeof d2 == 'string' && d2.constructor == String)){   
    125.   
    126.         var date2 = Date.isSimpleDate(d2)!=null?Date.isSimpleDate(d2):Date.isDateHH(d2);   
    127.         date2 = date2!=null?date2:Date.isDateHHMM(d2)   
    128.         date2 = date2!=null?date2:Date.isDateHHMMSS(d2);   
    129.         if(d1==null||date2==null){   
    130.             alert("日期格式不正确!");   
    131.             return false;   
    132.         }   
    133.         if(d1<=date2){   
    134.             return true;   
    135.         }else{   
    136.             return false;   
    137.         }   
    138.     }else{   
    139.         alert("无法判断输入数据类型!");   
    140.         return false;   
    141.     }   
    142. }  

     

    from:
    http://www.javaeye.com/topic/429365

    jstl,fmt标签总结

    jstl,fmt标签总结
    首先,jstl既然可以国际化,那么必然可以自动根据local设置来选择资源文件。
    2,fmt:setLocal 可以设置Local,从而改变输出格式。
    3,fmt:message 可以输出资源文件里的key对应的value。
     <fmt:message key=xxx"/>
    和struts一样 还可以传参数
     <fmt:message key=xxx"/>
      <fmt:param value="${abc}"/>
     </fmt:message>
    4,<fmt:bundle>
     <fmt:setBundle>
     这地方有点意思,首先我在工程的WEB-INF/classes下面建立了一个资源文件resources.properties。然后在jsp页面里
     <fmt:bundle basename="resources.properties">使用此资源文件。
     Nitrox插件提示找不到resources.properties的警告.
     使用<fmt:message key="xxx"/>也无法显示
     原因:工程没有指定input ,output的对应关系.这样classes并不是classpath路径.
     解决办法:
      设置input为/WEB-INF/src ,output /WEB-INF/classes
      然后把resources.properties放在 /WEB-INF/src/下面。
      这样在/WEB-INF/classes/下面自动生成了一个resources.properties.这就是我想要的。
      好了,在试一次,资源文件找到了。
        <fmt:message key="xxx"/>也能正常显示了。
    5,难道<fmt:message>必须和<fmt:bundle >搭配使用才行吗?实在觉得有点罗嗦。
        没办法,jstl就是这样用的。
    6,jstl使用资源文件有个大的问题,因为fmt:bundle basename="xxx" 指定死了资源文件了,那么如果local不同了
     岂不是还从这个资源文件里取数据吗?这样美国的网页浏览仍旧显示日文,就不合理了.
     我理解错了,<fmt:bundle basename="xxx"/>并非指定资源文件就是他,而是指资源文件的基本名字,例如,
     如果是英国的local那么自动查找xxx_en.properties,如果是中国的local那么自动去查找xxx_zh.properties.
     和struts是一样的.
     
    from:

    天津的日偏食

    昨天单位专门发了个日食观测镜,9:30的时候我专门在那瞅了几分钟,好像也就那样。
    8:40的时候太阳的右上角有一点没有,9:30的时候像一个粗写的左圆括号。
     
    没有日全食好看。
     
    cl说武汉全变黑了。
     
    这就是所谓的五百年一次,生活仍将继续。
     
    20/07/2009

    DIV样式

    <%@ page language="java" pageEncoding="UTF-8"%>


    <html>
     <head>
      <title>testStyle</title>
    <style type="text/css">
    .transparent1{
    filter:alpha(opacity=30);
    -moz-opacity:0.3;
    opacity:0.3;
    }

    .transparent2{
    filter:alpha(opacity=80);
    -moz-opacity:0.8;
    opacity:0.8;
    }
    </style>
      
      <SCRIPT language="JavaScript">
    var canmove=false;


    function clickButton()
    {
     var obj2 = document.getElementById("ttBox");
        obj2.size += 1;
    }

     

    function clickButton2()
    {
     var obj2 = document.getElementById("ttBox");
        obj2.style.color = "yellow";
    }

     

    //位置
    function clickButton3()
    {
     var obj2 = document.getElementById("testDIV1_1");
     var obj3 = document.getElementById("ttBox");

     //alert(obj2.innerHTML + obj2.style.left);
        //obj2.style.padding-left = "8px";
        //obj2.style.padding-top = "8px";
       
        obj2.style.left = "60px";
        obj2.style.top = "380px";
       
        obj2.innerHTML = obj2.innerHTML.replace("PADDING-LEFT: 8px;","PADDING-LEFT:16px;");
    }

     

    //透明度
    function clickButton4()
    {
     var obj2 = document.getElementById("testDIV1_1");
     var obj3 = document.getElementById("textBOX");
     //alert(obj2.innerHTML);
     
        //obj2.innerHTML = obj2.innerHTML.replace("FILTER: alpha(opacity=30)", "FILTER: alpha(opacity=80)");
        obj2.innerHTML = obj2.innerHTML.replace("transparent1", "transparent2");
        //obj3.class = "transparent2";
        //obj3.style.-moz-opacity = .8;
        //obj3.style.opacity = 0.8;
        //alert(obj3.className);
    }


    function moveit(e)
    {
     var evtobj=window.event? window.event : e;
     if (this.dragapproved==1)
     {
      this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
      this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
      return false
     }
    }

     

    </SCRIPT>

     </head>

     <body>
      
     
     

      <DIV id="testDIV">
       <DIV id="testDIV1_1" style="position: absolute;">
        <input type='textbox' name='textBOX' id="ttBox" title="tr" size="10"
         value="testText" class="transparent1"
         style="color: red; background-color: black; padding-left: 8px" />
       </DIV>


    <BR><BR>

       <input type='button' name='button1' value="大小"
        onclick="javascript:clickButton()" />

       <input type='button' name='button1' value="颜色"
        onclick="javascript:clickButton2()" />

       <input type='button' name='button1' value="位置"
        onclick="javascript:clickButton3()" />

       <input type='button' name='button1' value="透明度"
        onclick="javascript:clickButton4()" />
      </DIV>

      <div id="svg" style="width: 100px; height: 100px;">
      </div>

    <hr>
    <p><a href="index0.jsp">返回主页</a>
     </body>
    </html>

    直接贴代码;
    page4.jsp
    ------------------
     
     

    JSP中出现According to TLD or attribute directive in tag file

    2:如果要使用jstl1.1(推荐) 则按照一下修改,很简单的。


    jstl存在1.0和1.1的差异问题,用EL建议需要在1.1的版本下,

    使用jstl1.1 只需要将

    1.0的为

    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

    换成:

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


    注意,1.0版本没有/jsp/

     
    from:
    19/07/2009

    关于Spring的标记不能正常显示的问题

    最近在学习和Spring相关的问题,学得似懂非懂。
    首先是熟悉MVC框架,还好学得似乎懂了;其次学习Acegi安全系统;再次学习Spring+dao数据库操作。
     
    不过有个小问题一直困扰我。
     
    gw把单位的《Apring in Action中文版》给我看,里面知识介绍得还是挺全面的。
     
    我写dao程序时把Spring相应的地方改了一下,然后就出问题了。
     
    P249
    home.jsp
    ------------------
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page language="java" import="TT3.User"%>
    <%@ taglib uri="http://acegisecurity.org/authz" prefix="authz"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>My JSP 'home.jsp' starting page</title>
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->
      </head>
      <body>
        <h2>${info.username}</h2>
      </body>
    </html>
    testtomcat3-servlet.xml
    --------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <!--
      - Application context definition for "contacts" DispatcherServlet.
      -
      - $Id: contacts-servlet.xml 1754 2006-11-17 02:01:21Z benalex $
      -->
    <beans>
     <!-- ========================== WEB DEFINITIONS ======================= -->
     <bean id="homeController"
             class="TT3.HomeController">
        <property name="successView">
              <value>home</value>
     </property>
     <property name="formView">
      <value>home</value>
     </property>
               
     </bean>
     
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix">
         <value>/WEB-INF/jsp/</value>
       </property>
       <property name="suffix">
         <value>.jsp</value>
       </property>
     </bean>
    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
        <props>
          <prop key="/home.htm">homeController</prop>
        </props>
      </property>
    </bean>
    </beans>
    web.xml
    -----------------
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app>
        <display-name>Acegi Security Tutorial Application</display-name>
       
        <servlet>
       <servlet-name>testtomcat3</servlet-name>
       <servlet-class>
          org.springframework.web.servlet.DispatcherServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>testtomcat3</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
       
     <!--
       - Location of the XML file that defines the root application context
       - Applied by ContextLoaderListener.
       -->
     <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
       /WEB-INF/testtomcat3-servlet.xml,
       /WEB-INF/applicationContext-acegi-security.xml
      </param-value>
     </context-param>
     
        <filter>
            <filter-name>Acegi Filter Chain Proxy</filter-name>
            <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
            <init-param>
                <param-name>targetClass</param-name>
                <param-value>org.acegisecurity.util.FilterChainProxy</param-value>
            </init-param>
        </filter>
        <filter-mapping>
          <filter-name>Acegi Filter Chain Proxy</filter-name>
          <url-pattern>/*</url-pattern>
        </filter-mapping>
     
     <!--
       - Loads the root application context of this web app at startup.
       - The application context is then available via
       - WebApplicationContextUtils.getWebApplicationContext(servletContext).
        -->
     <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
     
      <servlet>
        <servlet-name>testAJAX</servlet-name>
        <servlet-class>TT3.testAJAX</servlet-class>
      </servlet>
      <servlet>
        <servlet-name>register</servlet-name>
        <servlet-class>TT3.dao.register</servlet-class>
      </servlet>

      <servlet-mapping>
        <servlet-name>testAJAX</servlet-name>
        <url-pattern>/servlet/testAJAX</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>register</servlet-name>
        <url-pattern>/register</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
     </welcome-file-list>
    </web-app>
    register.jsp
    -------------------
    <%@ page language="java" pageEncoding="UTF-8"%>
    <%@ page language="java" import="TT3.User"%>
    <%@ taglib uri="http://acegisecurity.org/authz" prefix="authz"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
     <base href="<%=basePath%>">
     <title>My JSF 'register.jsp' starting page</title>
     
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->
    <script language="JavaScript">
    function click2()
    {
        var obj = document.getElementById("frm");
        var objUser = document.getElementById("username");
        var objPassword = document.getElementById("password");
        if(objUser.value.length<1)
        {
         if(objPassword.value.length<1)
         {
          alert("请输入用户名和密码");
         }
         else
         {
          alert("请输入用户名");
         }
        }
        else if(objPassword.value.length<1)
        {
         alert("请输入密码");
        }
        else
        {
         obj.submit();
        }
    }
    function tab2()
    {
     var objUser2 = document.getElementById("user");
        //var objPassword2 = document.getElementById("password");
       
        //alert("tab ");
        var el = window.event.srcElement;
       
        //alert(el.id);
       
        if(el.id==objUser2.id && objUser2.value.length<1 && window.event.watch())
        {
         //alert("请输入你的用户名");
        }
    }
    </script>
    </head>
    <body>
    <form action="home.htm" method="post" id="frm">
    用户名:<input type="text" name="username" id="username">  <DIV id="hint"></DIV><br>
    密码:<input type="text" name="password" id="password">
    <input type="button" value="注册" onclick="javascript:click2();">
    </form>
    <hr>
    <p><a href="index0.jsp">返回主页</a>
    </body>
    </html>
     
     
    还有HomeController.java,User.java等文件的代码就不一一列出了,现在的问题就是home.htm页面中的${info.username}变量不能显示成输入的用户名,但是之前测试的时候用${message}是可以正常显示的。
     
    改了半天,似乎明白点道道来了。
     
    其中对于bean的申明:
     <bean id="homeController"
             class="TT3.HomeController">
        <property name="successView">
              <value>home</value>
     </property>
     <property name="formView">
      <value>home</value>
     </property>
               
     </bean>
    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
        <props>
          <prop key="/home.htm">homeController</prop>
        </props>
      </property>
    </bean>
     <bean name="/home.htm"
             class="TT3.HomeController">
        <property name="successView">
              <value>home</value>
     </property>
     <property name="formView">
      <value>home</value>
     </property>
               
     </bean>
    都是可以正常运行的,而且结果还是一样的。
     
    另外我那个${info.username}不能正常显示的问题只需要将<web-app>改成<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">就可以正常显示了。
     
    这里面还会涉及到缓存之类的一些问题,就是相同的程序一会运行正常,一会运行不正常,这里一般涉及到IE的缓存,Tomcat的缓存,还有Eclipse我不知道是否有缓存这一说。jetty操作方式和Tomcat几乎一模一样,或者说比Tomcat简单。
     
    问题解决了我一般会来个总结,或者说是胡思乱想几分钟。这个问题前几天也时常出现,当时好像就是<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">这一句老是报错,改成<web-app>就没事了,没想到改了后会出现我意想不到的错误。而且这个错误我还一点思路都没有,前三天还是什么时候解决也不知道是怎么解决的,而且即便解决了也没知道解决的思路和出错的原因。我就又开始思考是先出错再去解决错误还是先解决所有可能会出现的错误让错误不能出现哪个好些。不过既然错误能够事先解决那它或许就不能叫错误吧,既然已经出现了那它就有出现的理由,事先不能预料所有的错误,所以写程序基本上也是个排错的过程;如果以上思索成立的话,将程序中出现的错误换成现实生活中的其他问题,结果又会怎样,这又是个问题,想着头大,所以干脆不想。
    16/07/2009

    Servlet如何获取form里的参数

    很弱的一个问题,我在网上居然没找到答案,可能是大家觉得太简单不值得写吧。
    在HTML页面中,
    <input type="text" name="user"><br>
    这里面的name不能改为id,否则Servlet里面的resquest.getParameter("user")方法将不能获得正确的值。
     
    相关的文件:
     
    register.jsp
    -------------------------
    <%@ page language="java" pageEncoding="UTF-8"%>

    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
     <base href="<%=basePath%>">
     <title>My JSF 'register.jsp' starting page</title>
     
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->
    </head>
     
    <body>
    <form action="register" method="post">
    用户名:<input type="text" name="user"><br>
    密码:<input type="text" name="password">
    <input type="submit">
    </form>
    </body>
    </html>

    register.java (Servlet)
    ---------------------------
    package TT3.dao;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class register extends HttpServlet {
     /**
      * Constructor of the object.
      */
     public register() {
      super();
     }
     /**
      * Destruction of the servlet. <br>
      */
     public void destroy() {
      super.destroy(); // Just puts "destroy" string in log
     }
     public void doGet(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
      doPost(request, response);
     }
     public void doPost(HttpServletRequest request, HttpServletResponse response)
       throws ServletException, IOException {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      
      String strUser = request.getParameter("user");
      String strPassword = request.getParameter("password");
      
      out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
      out.println("<HTML>");
      out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
      out.println("  <BODY>");
      out.print("    This is ");
      out.print(this.getClass());
      out.println(", using the POST method");
      
      out.println("user:" +strUser);
      out.println("password:" +strPassword);
      
      out.println("  </BODY>");
      out.println("</HTML>");
      out.flush();
      out.close();
     }
     /**
      * Initialization of the servlet. <br>
      *
      * @throws ServletException if an error occurs
      */
     public void init() throws ServletException {
      // Put your code here
     }
    }
    13/07/2009

    Bean class [net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl] not found

    昨天将spring部署好了,今天开始部署Acegi security,上午先看了半天相关介绍,下午开始硬着头皮部署。
    如意料中地我又得到了许多报错信息。
     
    2009-7-13 13:43:48 org.apache.catalina.core.AprLifecycleListener init
    信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_02\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin
    2009-7-13 13:43:48 org.apache.coyote.http11.Http11Protocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2009-7-13 13:43:48 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 506 ms
    2009-7-13 13:43:48 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2009-7-13 13:43:48 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.14
    2009-7-13 13:43:48 org.apache.catalina.startup.HostConfig deployWAR
    信息: Deploying web application archive contacts.war
    2009-7-13 13:43:49 org.apache.catalina.core.ApplicationContext log
    信息: Loading Spring root WebApplicationContext
    [WARN,ConfigurationFactory,main] No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/contacts/WEB-INF/lib/ehcache-1.2.4.jar!/ehcache-failsafe.xml
    [DEBUG,ContactDaoSpring$ContactInsert,main] RdbmsOperation with SQL [INSERT INTO contacts VALUES (?, ?, ?)] compiled
    [DEBUG,ContactDaoSpring$ContactInsert,main] RdbmsOperation with SQL [INSERT INTO contacts VALUES (?, ?, ?)] compiled
    [DEBUG,ContactDaoSpring$ContactUpdate,main] RdbmsOperation with SQL [UPDATE contacts SET contact_name = ?, address = ? WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactUpdate,main] RdbmsOperation with SQL [UPDATE contacts SET contact_name = ?, address = ? WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactDelete,main] RdbmsOperation with SQL [DELETE FROM contacts WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactDelete,main] RdbmsOperation with SQL [DELETE FROM contacts WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactsAllQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts ORDER BY id] compiled
    [DEBUG,ContactDaoSpring$ContactsAllQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts ORDER BY id] compiled
    [DEBUG,ContactDaoSpring$PrincipalsAllQuery,main] RdbmsOperation with SQL [SELECT username FROM users ORDER BY username] compiled
    [DEBUG,ContactDaoSpring$PrincipalsAllQuery,main] RdbmsOperation with SQL [SELECT username FROM users ORDER BY username] compiled
    [DEBUG,ContactDaoSpring$RolesAllQuery,main] RdbmsOperation with SQL [SELECT DISTINCT authority FROM authorities ORDER BY authority] compiled
    [DEBUG,ContactDaoSpring$RolesAllQuery,main] RdbmsOperation with SQL [SELECT DISTINCT authority FROM authorities ORDER BY authority] compiled
    [DEBUG,ContactDaoSpring$ContactsByIdQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts WHERE id = ? ORDER BY id] compiled
    [DEBUG,ContactDaoSpring$ContactsByIdQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts WHERE id = ? ORDER BY id] compiled
    2009-7-13 13:43:51 org.apache.catalina.core.ApplicationContext log
    信息: Set web app root system property: 'webapp.root' = [C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\contacts\]
    2009-7-13 13:43:51 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Log4J from [C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\contacts\WEB-INF\classes\log4j.properties]
    2009-7-13 13:43:51 org.apache.catalina.core.ApplicationContext log
    信息: Loading WebApplicationContext for Spring FrameworkServlet 'contacts'
    2009-7-13 13:43:52 org.apache.catalina.core.ApplicationContext log
    信息: Loading WebApplicationContext for Spring FrameworkServlet 'remoting'
    2009-7-13 13:43:53 org.springframework.web.context.ContextLoader initWebApplicationContext
    信息: Root WebApplicationContext: initialization started
    2009-7-13 13:43:53 org.apache.catalina.core.ApplicationContext log
    信息: Loading Spring root WebApplicationContext
    2009-7-13 13:43:53 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/testtomcat3-servlet.xml]
    2009-7-13 13:43:53 org.springframework.web.context.ContextLoader initWebApplicationContext
    严重: Context initialization failed
    org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'authenticationDao' defined in ServletContext resource [/WEB-INF/testtomcat3-servlet.xml]: Bean class [net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl] not found; nested exception is java.lang.ClassNotFoundException: net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl
    java.lang.ClassNotFoundException: net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:247)
     at org.springframework.util.ClassUtils.forName(ClassUtils.java:108)
     at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:65)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:426)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:392)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:307)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:191)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:126)
     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
     at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
     at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
     at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
     at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
     at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
     at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
     at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
     at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
     at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
     at org.apache.catalina.core.StandardService.start(StandardService.java:516)
     at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
     at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2009-7-13 13:43:53 org.apache.catalina.core.StandardContext listenerStart
    严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
    org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'authenticationDao' defined in ServletContext resource [/WEB-INF/testtomcat3-servlet.xml]: Bean class [net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl] not found; nested exception is java.lang.ClassNotFoundException: net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl
    java.lang.ClassNotFoundException: net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:247)
     at org.springframework.util.ClassUtils.forName(ClassUtils.java:108)
     at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:65)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:426)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:392)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:307)
     at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:191)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:126)
     at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
     at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
     at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
     at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
     at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
     at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
     at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
     at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
     at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
     at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
     at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
     at org.apache.catalina.core.StandardService.start(StandardService.java:516)
     at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
     at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2009-7-13 13:43:53 org.apache.catalina.core.StandardContext start
    严重: Error listenerStart
    2009-7-13 13:43:53 org.apache.catalina.core.StandardContext start
    严重: Context [/TestTomcat3] startup failed due to previous errors
    2009-7-13 13:43:53 org.apache.catalina.core.ApplicationContext log
    信息: Closing Spring root WebApplicationContext
    2009-7-13 13:43:53 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2009-7-13 13:43:53 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2009-7-13 13:43:53 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/31  config=null
    2009-7-13 13:43:53 org.apache.catalina.startup.Catalina start
    信息: Server startup in 4686 ms

    相关文件
    WEB-INF
    web.xml
    ---------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
       <servlet-name>testtomcat3</servlet-name>
       <servlet-class>
          org.springframework.web.servlet.DispatcherServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>testtomcat3</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
     
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/testtomcat3-servlet.xml</param-value>
    </context-param>
     

      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

    testtomcat3-servlet.xml
    ----------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <!--
      - Application context definition for "contacts" DispatcherServlet.
      -
      - $Id: contacts-servlet.xml 1754 2006-11-17 02:01:21Z benalex $
      -->
    <beans>
     <!-- ========================== WEB DEFINITIONS ======================= -->
     <bean id="homeController"
             class="TT3.HomeController">
          <property name="greeting">
            <value>Welcome to Spring Training!</value>
          </property>
     </bean>
     
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix">
         <value>/WEB-INF/jsp/</value>
       </property>
       <property name="suffix">
         <value>.jsp</value>
       </property>
     </bean>
    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
        <props>
          <prop key="/home.htm">homeController</prop>
        </props>
      </property>
    </bean>
    <bean id="authenticationDao"
     class="net.sf.acegisecurity.providers.dao.jdbc.JdbcDaoImpl">
     <property name="dataSource">
       <ref bean="dataSource"/>
     </property>
        <property name="usersByUserNameQuery">
          <value>SELECT login,password FROM student WHERE login=?</value>
        </property>
        <property name="usersByUserNameMapping">
          <bean class="TT3.UsersByUsernameMapping"/>
        </property>
    </bean>
    </beans>


    applicationContext-acegi-security.xml
    -------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <!--
      - Application context containing authentication, channel
      - security and web URI beans.
      -
      - Only used by "filter" artifact.
      -
      - $Id: applicationContext-acegi-security.xml 1425 2006-04-28 06:43:50Z benalex $
      -->
    <beans>
       <!-- ======================== FILTER CHAIN ======================= -->
     <!--  if you wish to use channel security, add "channelProcessingFilter," in front
           of "httpSessionContextIntegrationFilter" in the list below -->
     <bean id="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
          <property name="filterInvocationDefinitionSource">
             <value><![CDATA[
          CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
          PATTERN_TYPE_APACHE_ANT
                /**=httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,basicProcessingFilter,securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter,switchUserProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
             ]]></value>
          </property>
        </bean>
       <!-- ======================== AUTHENTICATION ======================= -->
       <bean id="authenticationManager" class="org.acegisecurity.providers.ProviderManager">
          <property name="providers">
             <list>
                <ref local="daoAuthenticationProvider"/>
                <ref local="anonymousAuthenticationProvider"/>
                 <ref local="rememberMeAuthenticationProvider"/>
             </list>
          </property>
       </bean>
       <bean id="jdbcDaoImpl" class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl">
          <property name="dataSource"><ref bean="dataSource"/></property>
       </bean>
       <bean id="passwordEncoder" class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"/>
       <bean id="daoAuthenticationProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider">
          <property name="userDetailsService"><ref local="jdbcDaoImpl"/></property>
    <!--      <property name="userCache"><ref local="userCache"/></property> -->
          <property name="passwordEncoder"><ref local="passwordEncoder"/></property>
       </bean>
    <!--
       <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>
       <bean id="userCacheBackend" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
          <property name="cacheManager">
             <ref local="cacheManager"/>
          </property>
          <property name="cacheName">
             <value>userCache</value>
          </property>
       </bean>
       <bean id="userCache" class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
          <property name="cache"><ref local="userCacheBackend"/></property>
       </bean>
    -->
       <!-- Automatically receives AuthenticationEvent messages -->
       <bean id="loggerListener" class="org.acegisecurity.event.authentication.LoggerListener"/>
       <bean id="basicProcessingFilter" class="org.acegisecurity.ui.basicauth.BasicProcessingFilter">
          <property name="authenticationManager"><ref local="authenticationManager"/></property>
          <property name="authenticationEntryPoint"><ref local="basicProcessingFilterEntryPoint"/></property>
       </bean>
       <bean id="basicProcessingFilterEntryPoint" class="org.acegisecurity.ui.basicauth.BasicProcessingFilterEntryPoint">
          <property name="realmName"><value>Contacts Realm</value></property>
       </bean>
       <bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
          <property name="key"><value>foobar</value></property>
          <property name="userAttribute"><value>anonymousUser,ROLE_ANONYMOUS</value></property>
       </bean>
       <bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
          <property name="key"><value>foobar</value></property>
       </bean>
       <bean id="httpSessionContextIntegrationFilter" class="org.acegisecurity.context.HttpSessionContextIntegrationFilter">
       </bean>
       <bean id="rememberMeProcessingFilter" class="org.acegisecurity.ui.rememberme.RememberMeProcessingFilter">
          <property name="authenticationManager"><ref local="authenticationManager"/></property>
          <property name="rememberMeServices"><ref local="rememberMeServices"/></property>
       </bean>
       <bean id="rememberMeServices" class="org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices">
          <property name="userDetailsService"><ref local="jdbcDaoImpl"/></property>
          <property name="key"><value>springRocks</value></property>
       </bean>
       <bean id="rememberMeAuthenticationProvider" class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider">
          <property name="key"><value>springRocks</value></property>
       </bean>
       <bean id="logoutFilter" class="org.acegisecurity.ui.logout.LogoutFilter">
          <constructor-arg value="/index.jsp"/> <!-- URL redirected to after logout -->
          <constructor-arg>
             <list>
                  <ref bean="rememberMeServices"/>
                  <bean class="org.acegisecurity.ui.logout.SecurityContextLogoutHandler"/>
             </list>
          </constructor-arg>
       </bean>
       <bean id="securityContextHolderAwareRequestFilter" class="org.acegisecurity.wrapper.SecurityContextHolderAwareRequestFilter"/>
       <!-- ===================== HTTP CHANNEL REQUIREMENTS ==================== -->
       <!-- You will need to uncomment the "Acegi Channel Processing Filter"
            <filter-mapping> in web.xml for the following beans to be used -->
       <bean id="channelProcessingFilter" class="org.acegisecurity.securechannel.ChannelProcessingFilter">
          <property name="channelDecisionManager"><ref local="channelDecisionManager"/></property>
          <property name="filterInvocationDefinitionSource">
             <value><![CDATA[
           CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
        \A/secure/.*\Z=REQUIRES_SECURE_CHANNEL
        \A/acegilogin.jsp.*\Z=REQUIRES_SECURE_CHANNEL
        \A/j_acegi_security_check.*\Z=REQUIRES_SECURE_CHANNEL
        \A.*\Z=REQUIRES_INSECURE_CHANNEL
             ]]></value>
          </property>
       </bean>
       <bean id="channelDecisionManager" class="org.acegisecurity.securechannel.ChannelDecisionManagerImpl">
          <property name="channelProcessors">
             <list>
                <ref local="secureChannelProcessor"/>
                <ref local="insecureChannelProcessor"/>
             </list>
          </property>
       </bean>
       <bean id="secureChannelProcessor" class="org.acegisecurity.securechannel.SecureChannelProcessor"/>
       <bean id="insecureChannelProcessor" class="org.acegisecurity.securechannel.InsecureChannelProcessor"/>
       <!-- ===================== HTTP REQUEST SECURITY ==================== -->
       <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter">
          <property name="authenticationEntryPoint"><ref local="authenticationProcessingFilterEntryPoint"/></property>
          <property name="accessDeniedHandler">
           <bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl">
            <property name="errorPage" value="/accessDenied.jsp"/>
           </bean>
          </property>
       </bean>
       <bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="authenticationFailureUrl"><value>/acegilogin.jsp?login_error=1</value></property>
          <property name="defaultTargetUrl"><value>/</value></property>
          <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
          <property name="rememberMeServices"><ref local="rememberMeServices"/></property>
       </bean>
       <bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
          <property name="loginFormUrl"><value>/acegilogin.jsp</value></property>
          <property name="forceHttps"><value>false</value></property>
       </bean>
       <bean id="httpRequestAccessDecisionManager" class="org.acegisecurity.vote.AffirmativeBased">
          <property name="allowIfAllAbstainDecisions"><value>false</value></property>
          <property name="decisionVoters">
             <list>
                <ref bean="roleVoter"/>
             </list>
          </property>
       </bean>
       <!-- Note the order that entries are placed against the objectDefinitionSource is critical.
            The FilterSecurityInterceptor will work from the top of the list down to the FIRST pattern that matches the request URL.
            Accordingly, you should place MOST SPECIFIC (ie a/b/c/d.*) expressions first, with LEAST SPECIFIC (ie a/.*) expressions last -->
       <bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
          <property name="authenticationManager"><ref bean="authenticationManager"/></property>
          <property name="accessDecisionManager"><ref local="httpRequestAccessDecisionManager"/></property>
          <property name="objectDefinitionSource">
             <value><![CDATA[
           CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
           PATTERN_TYPE_APACHE_ANT
           /index.jsp=ROLE_ANONYMOUS,ROLE_USER
           /hello.htm=ROLE_ANONYMOUS,ROLE_USER
           /logoff.jsp=ROLE_ANONYMOUS,ROLE_USER
           /switchuser.jsp=ROLE_SUPERVISOR
           /j_acegi_switch_user=ROLE_SUPERVISOR
           /acegilogin.jsp*=ROLE_ANONYMOUS,ROLE_USER
        /**=ROLE_USER
             ]]></value>
          </property>
       </bean>
       <!-- Filter used to switch the user context. Note: the switch and exit url must be secured
            based on the role granted the ability to 'switch' to another user -->
       <!-- In this example 'marissa' has ROLE_SUPERVISOR that can switch to regular ROLE_USER(s) -->
       <bean id="switchUserProcessingFilter" class="org.acegisecurity.ui.switchuser.SwitchUserProcessingFilter">
          <property name="userDetailsService" ref="jdbcDaoImpl" />
       <property name="switchUserUrl"><value>/j_acegi_switch_user</value></property>
       <property name="exitUserUrl"><value>/j_acegi_exit_user</value></property>
       <property name="targetUrl"><value>/acegi-security-sample-contacts-filter/secure/index.htm</value></property>
       </bean>
    </beans>
    UsersByUsernameMapping.java
    -----------------------------------------

    package TT3;

    import java.sql.SQLException;
    import java.sql.Types;

    import javax.resource.cci.ResultSet;
    import javax.sql.DataSource;

    import org.acegisecurity.GrantedAuthority;
    import org.acegisecurity.GrantedAuthorityImpl;
    import org.acegisecurity.userdetails.User;
    import org.acegisecurity.userdetails.UserDetails;
    import org.springframework.jdbc.core.SqlParameter;
    import org.springframework.jdbc.object.MappingSqlQuery;


    public class UsersByUsernameMapping extends MappingSqlQuery {
     protected UsersByUsernameMapping(DataSource dataSource) {
      super(dataSource, usersByUsernameQuery);
      declareParameter(new SqlParameter(Types.VARCHAR));

      compile();
     }
     
     protected Object mapRow(ResultSet rs, int rownum)
      throws SQLException {
      String username = rs.getString(1);
      String password = rs.getString(2);
      
      UserDetails user = new User(username, password, true,
        new GrantedAuthority[]
         {new GrantedAuthorityImpl("HOLDER")});
      
      return user;
     }
    }

    HomeController.java
    -----------------------------------------
    package TT3;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;

    public class HomeController implements Controller{
     
     public ModelAndView handleRequest(HttpServletRequest request,
       HttpServletResponse response) throws Exception {
      return new ModelAndView("home","message",greeting);
     }
     
     private String greeting;
     
     public void setGreeting(String greeting) {
      this.greeting = greeting;
     }
    }


    [2009-07-13 13:56]

     

     

     
    12/07/2009

    Error loading WebappClassLoader

    部署Spring时报了一堆错误。
     
    2009-7-12 16:19:04 org.apache.catalina.core.AprLifecycleListener init
    信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_02\bin;C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin
    2009-7-12 16:19:04 org.apache.coyote.http11.Http11Protocol init
    信息: Initializing Coyote HTTP/1.1 on http-8080
    2009-7-12 16:19:04 org.apache.catalina.startup.Catalina load
    信息: Initialization processed in 515 ms
    2009-7-12 16:19:04 org.apache.catalina.core.StandardService start
    信息: Starting service Catalina
    2009-7-12 16:19:04 org.apache.catalina.core.StandardEngine start
    信息: Starting Servlet Engine: Apache Tomcat/6.0.14
    2009-7-12 16:19:04 org.apache.catalina.startup.HostConfig deployWAR
    信息: Deploying web application archive contacts.war
    2009-7-12 16:19:04 org.apache.catalina.core.ApplicationContext log
    信息: Loading Spring root WebApplicationContext
    [WARN,ConfigurationFactory,main] No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/C:/Program%20Files/Apache%20Software%20Foundation/Tomcat%206.0/webapps/contacts/WEB-INF/lib/ehcache-1.2.4.jar!/ehcache-failsafe.xml
    [DEBUG,ContactDaoSpring$ContactInsert,main] RdbmsOperation with SQL [INSERT INTO contacts VALUES (?, ?, ?)] compiled
    [DEBUG,ContactDaoSpring$ContactInsert,main] RdbmsOperation with SQL [INSERT INTO contacts VALUES (?, ?, ?)] compiled
    [DEBUG,ContactDaoSpring$ContactUpdate,main] RdbmsOperation with SQL [UPDATE contacts SET contact_name = ?, address = ? WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactUpdate,main] RdbmsOperation with SQL [UPDATE contacts SET contact_name = ?, address = ? WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactDelete,main] RdbmsOperation with SQL [DELETE FROM contacts WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactDelete,main] RdbmsOperation with SQL [DELETE FROM contacts WHERE id = ?] compiled
    [DEBUG,ContactDaoSpring$ContactsAllQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts ORDER BY id] compiled
    [DEBUG,ContactDaoSpring$ContactsAllQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts ORDER BY id] compiled
    [DEBUG,ContactDaoSpring$PrincipalsAllQuery,main] RdbmsOperation with SQL [SELECT username FROM users ORDER BY username] compiled
    [DEBUG,ContactDaoSpring$PrincipalsAllQuery,main] RdbmsOperation with SQL [SELECT username FROM users ORDER BY username] compiled
    [DEBUG,ContactDaoSpring$RolesAllQuery,main] RdbmsOperation with SQL [SELECT DISTINCT authority FROM authorities ORDER BY authority] compiled
    [DEBUG,ContactDaoSpring$RolesAllQuery,main] RdbmsOperation with SQL [SELECT DISTINCT authority FROM authorities ORDER BY authority] compiled
    [DEBUG,ContactDaoSpring$ContactsByIdQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts WHERE id = ? ORDER BY id] compiled
    [DEBUG,ContactDaoSpring$ContactsByIdQuery,main] RdbmsOperation with SQL [SELECT id, contact_name, email FROM contacts WHERE id = ? ORDER BY id] compiled
    2009-7-12 16:19:07 org.apache.catalina.core.ApplicationContext log
    信息: Set web app root system property: 'webapp.root' = [C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\contacts\]
    2009-7-12 16:19:07 org.apache.catalina.core.ApplicationContext log
    信息: Initializing Log4J from [C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\contacts\WEB-INF\classes\log4j.properties]
    2009-7-12 16:19:07 org.apache.catalina.core.ApplicationContext log
    信息: Loading WebApplicationContext for Spring FrameworkServlet 'contacts'
    2009-7-12 16:19:07 org.apache.catalina.core.ApplicationContext log
    信息: Loading WebApplicationContext for Spring FrameworkServlet 'remoting'
    2009-7-12 16:19:08 org.springframework.web.context.ContextLoader initWebApplicationContext
    信息: Root WebApplicationContext: initialization started
    2009-7-12 16:19:08 org.apache.catalina.core.ApplicationContext log
    信息: Loading Spring root WebApplicationContext
    2009-7-12 16:19:08 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    信息: Loading XML bean definitions from ServletContext resource [/WEB-INF/TestTomcat3-servlet.xml]
    2009-7-12 16:19:08 org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
    信息: Bean factory for application context [Root WebApplicationContext]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [/home.htm,viewResolver]; root of BeanFactory hierarchy
    2009-7-12 16:19:08 org.springframework.context.support.AbstractApplicationContext refresh
    信息: 2 beans defined in application context [Root WebApplicationContext]
    2009-7-12 16:19:08 org.springframework.context.support.AbstractApplicationContext initMessageSource
    信息: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@1ef4b]
    2009-7-12 16:19:08 org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
    信息: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1987298]
    2009-7-12 16:19:08 org.springframework.ui.context.support.UiApplicationContextUtils initThemeSource
    信息: Unable to locate ThemeSource with name 'themeSource': using default [org.springframework.ui.context.support.ResourceBundleThemeSource@992725]
    2009-7-12 16:19:08 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    信息: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [/home.htm,viewResolver]; root of BeanFactory hierarchy]
    2009-7-12 16:19:08 org.springframework.web.context.ContextLoader initWebApplicationContext
    信息: Using context class [org.springframework.web.context.support.XmlWebApplicationContext] for root WebApplicationContext
    2009-7-12 16:19:08 org.springframework.web.context.ContextLoader initWebApplicationContext
    信息: Root WebApplicationContext: initialization completed in 375 ms
    2009-7-12 16:19:08 org.apache.catalina.core.ApplicationContext log
    信息: Marking servlet TestTomcat3 as unavailable
    2009-7-12 16:19:08 org.apache.catalina.core.ApplicationContext log
    严重: Error loading WebappClassLoader
      delegate: false
      repositories:
        /WEB-INF/classes/
    ----------> Parent Classloader:
    org.apache.catalina.loader.StandardClassLoader@94884d
     org.springframework.we.servlet.DispatcherServlet
    java.lang.ClassNotFoundException: org.springframework.we.servlet.DispatcherServlet
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
     at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
     at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
     at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
     at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
     at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
     at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
     at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
     at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
     at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
     at org.apache.catalina.core.StandardService.start(StandardService.java:516)
     at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
     at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2009-7-12 16:19:08 org.apache.catalina.core.StandardContext loadOnStartup
    严重: Servlet /TestTomcat3 threw load() exception
    java.lang.ClassNotFoundException: org.springframework.we.servlet.DispatcherServlet
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
     at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
     at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
     at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4045)
     at org.apache.catalina.core.StandardContext.start(StandardContext.java:4351)
     at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
     at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
     at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
     at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
     at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
     at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
     at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
     at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
     at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
     at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
     at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
     at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
     at org.apache.catalina.core.StandardService.start(StandardService.java:516)
     at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
     at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)
     at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
     at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    2009-7-12 16:19:08 org.apache.coyote.http11.Http11Protocol start
    信息: Starting Coyote HTTP/1.1 on http-8080
    2009-7-12 16:19:08 org.apache.jk.common.ChannelSocket init
    信息: JK: ajp13 listening on /0.0.0.0:8009
    2009-7-12 16:19:08 org.apache.jk.server.JkMain start
    信息: Jk running ID=0 time=0/31  config=null
    2009-7-12 16:19:08 org.apache.catalina.startup.Catalina start
    信息: Server startup in 4513 ms
    相关文件
    WEB-INF/
     
    web.xml
    ------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <servlet>
       <servlet-name>TestTomcat3</servlet-name>
       <servlet-class>
          org.springframework.we.servlet.DispatcherServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>TestTomcat3</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>
    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
     
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/TestTomcat3-servlet.xml</param-value>
    </context-param>
     

      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
     
    TestTomcat3-Servlet.xml
    ---------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--
      - Application context definition for "contacts" DispatcherServlet.
      -
      - $Id: contacts-servlet.xml 1754 2006-11-17 02:01:21Z benalex $
      -->

    <beans>

     <!-- ========================== WEB DEFINITIONS ======================= -->
     <bean name="/home.htm"
             class="TT3.HomeController">
          <property name="greeting">
            <value>Welcome to Spring Training!</value>
          </property>
     </bean>
     
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix">
         <value>/WEB-INF/jsp</value>
       </property>
       <property name="suffix">
         <value>.jsp</value>
       </property>
     </bean>
    </beans>

    WEB-INF/jsp/
    home.jsp
    ---------------------------

    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>My JSP 'home.jsp' starting page</title>

     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->

      </head>
     
      <body>
        <h2>${message}</h2>
      </body>
    </html>


    src/TT3/
    HomeController.java
    -----------------------------
    package TT3;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;

    public class HomeController implements Controller{
     
     public ModelAndView handleRequest(HttpServletRequest request,
       HttpServletResponse response) throws Exception {
      return new ModelAndView("home","message",greeting);
     }
     
     private String greeting;
     
     public void setGreeting(String greeting) {
      this.greeting = greeting;
     }
    }

    WEB-INF\lib文件夹下的文件有:
    acegi-security-1.0.7.jar
    commons-codec-1.3.jar
    derby-hibernatedialect.jar
    spring.jar

    还不知道这个错误什么时候才能解决。
    2009-07-12 16:28


     
     解决办法:
    web.xml中的
    org.springframework.we.servlet.DispatcherServlet
    改为
    org.springframework.web.servlet.DispatcherServlet
    另外spring的.jar包有许多个都需要拷贝到lib目录下(由zy提供)。
    更改之后的web.xml和TestTomcat3.xml如下(参考意见主要由gw提供):
    web.xml
    --------------------------------------------------

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


    <servlet>
       <servlet-name>testtomcat3</servlet-name>
       <servlet-class>
          org.springframework.web.servlet.DispatcherServlet
       </servlet-class>
       <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>testtomcat3</servlet-name>
    <url-pattern>*.htm</url-pattern>
    </servlet-mapping>

    <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

     

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/testtomcat3-servlet.xml</param-value>
    </context-param>

     


      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

     

    testtomcat3.xml

    ----------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <!--
      - Application context definition for "contacts" DispatcherServlet.
      -
      - $Id: contacts-servlet.xml 1754 2006-11-17 02:01:21Z benalex $
      -->

    <beans>

     <!-- ========================== WEB DEFINITIONS ======================= -->
     <bean id="homeController"
             class="TT3.HomeController">
          <property name="greeting">
            <value>Welcome to Spring Training!</value>
          </property>
     </bean>
     
     <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="prefix">
         <value>/WEB-INF/jsp/</value>
       </property>
       <property name="suffix">
         <value>.jsp</value>
       </property>
     </bean>

    <bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
        <props>
          <prop key="/home.htm">homeController</prop>
        </props>
      </property>
    </bean>

    </beans>


     

    参考文献:
    Spring in Action中文版,人民邮电出版社,【美】Craig Walls Ryan Breidenbach 著;李磊  程立 译,2006,P241-P253
    [DONE 2009-07-13 09:04]

     
    10/07/2009

    [174 javajni.c] [error] 找不到指定的模块。

    问题描述:
    [2009-07-10 14:43:01] [174  javajni.c] [error] 找不到指定的模块。
    [2009-07-10 14:43:01] [986  prunsrv.c] [error] Failed creating java C:\Program Files\Java\jre1.6.0_02\bin\client\jvm.dll
    [2009-07-10 14:43:01] [1260 prunsrv.c] [error] ServiceStart returned 1
    解决办法:

    基本确定原因是JDK1.6和tomcat5.5之间的兼容性问题
    将JDK1.6目录下BIN文件夹中的msvcr71.dll复制到tomcat中BIN文件夹中。

     
    original from:
    09/07/2009

    javabean的使用

    小小地郁闷一下,刚才测试javaBean的使用方法,一试一个头大,一会是JSTL的版本不对,
    一会我又将<jsp:javaBean ...>写成了<jsp:javabean ...>,但是问题仍没解决,最后试了下
    将我自己的类不放在默认包下,终于成功了。
    以下是相关的代码及文件。
     
    login.jsp
    ---------------------------------
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
       
        <title>登录</title>
       
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->

      </head>
     
      <body>
      <center>
        <form name="user" action="login2.jsp" method="post">
        <TABLE border=0>
        <TR align=center>
        <TD>用户名:</TD><TD><INPUT name="name" value=""/></TD>
        </TR>
        <TR>
        <TD>密码:</TD><TD><INPUT name="password" value="" type="password" maxlength="50"/></TD>
        </TR>
        <TR align="center">
        <TD colspan=3><input type=submit value="登录"></TD>
        </TR>
    </TABLE>
    </form>
    </center>
      </body>
    </html>
     
     
    login2.jsp
    ----------------------------------------
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/core" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
       
        <title>My JSP 'login2.jsp' starting page</title>
       
     <meta http-equiv="pragma" content="no-cache">
     <meta http-equiv="cache-control" content="no-cache">
     <meta http-equiv="expires" content="0">   
     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
     <meta http-equiv="description" content="This is my page">
     <!--
     <link rel="stylesheet" type="text/css" href="styles.css">
     -->
     
       
    <jsp:useBean id="myenv" scope="session" class="test.user2" />
     
     <%
    // <jsp:usebean id="myenv" scope="session" class="cUser"/>
     String strName = request.getParameter("name");
        String strPassword = request.getParameter("password");
       
        myenv.setUser(strName);
     %>
      </head>
     
      <body>
      <%
      out.println(strName);
      %>
        name:<c:out value="${myenv.user}"/><BR>
        password:<c:out value="s3"/>
      </body>
    </html>
     

    user2.java
    -----------------------------
    package test;
    public class user2 {
     private String user = "";
     
     
     
     public user2() {
      user="";
     }
     
     public user2(String user) {
      this.user = user;
     }
     
     
     
     public void setUser(String user)
     {
      this.user = user;
     }
     
     public String getUser() {
      return user;
     }
    }
     

    如何部署jstl1.1

    1. 下载jakarta-taglibs-standard-1.1.2.zip
    (http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/jakarta-taglibs-standard-1.1.2.zip)
    2. 解压后,将standard.jar和jstl.jar文件拷贝到\WEB-INF\lib\
    3. 将jakarta-taglibs-standard-1.1.2\tld\下的tld类型文件拷到"\WEB-INF\tlds"下(1.1是15个)
    4. 在\WEB-INF\下建立web.xml文件中添加如下语句:
          <jsp-config>
              <taglib>
                  <taglib-uri>http://java.sun.com/jsp/core</taglib-uri>
                  <taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
              </taglib>
          </jsp-config>
    5. 在.jsp的前面加入如下语句
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/core" %>
    08/07/2009

    Top Ten Algorithms of the 20th Century(转)

     

    Top Ten Algorithms of the 20th Century

         Algos is the Greek word for pain. Algor is Latin, to be cold. Neither is the root for algorithm, which stems instead from al-Khwarizmi, the name of the ninth-century Arab scholar whose book al-jabrwa’l muqabalah devolved into today’s high school algebra textbooks. Al-Khwarizmi stressed the importance of methodical rocedures for solving problems. Were he around today,he’d no doubt be impressed by the advances in his eponymous approach.
          Some of the very best algorithms of the computer age are highlighted in the January/February 2000 issue of Computing in Science & Engineering, a joint publication of the American Institute of Physics and the IEEE Computer Society. Guest editors Jack Dongarra of the University of Tennessee and Oak Ridge National Laboratory and Francis Sullivan of the Center for Computing Sciences at the Institute for Defense Analyses put together a list they call the “Top Ten Algorithms of the Century.”
         “We tried to assemble the 10 algorithms with the greatest influence on the development and practice of science and engineering in the 20th century,” Dongarra and Sullivan write. As with any top-10 list, their selections—and non-selections—are bound to be controversial, they acknowledge. When it comes to picking the algorithmic best, there seems to be no best algorithm.
         Without further ado, here’s the CiSE top-10 list, in chronological order. (Dates and names associated with the algorithms should be read as first-order a
    pproximations. Most algorithms take shape over time, with many contributors.)

    1. Monte Carlo method(1946 蒙特卡罗算法)

    1946: John von Neumann, Stan Ulam, and Nick Metropolis, all at the Los Alamos Scientific Laboratory, cook up the Metropolis algorithm, also known as the Monte Carlo method. The Metropolis algorithm aims to obtain approximate solutions to numerical problems with unmanageably many degrees of freedom and to combinatorial problems of factorial size, by mimicking a random process. Given the digital computer’s reputation for deterministic calculation, it’s fitting that one of its earliest applications was the generation of random numbers.
       
    2. Simplex method(1947 单纯形算法)

    1947: George Dantzig, at the RAND Corporation, creates the simplex method for linear programming. In terms of widespread application, Dantzig’s algorithm is one of the most successful of all time: Linear programming dominates the world of industry, where economic survival depends on the ability to optimize within budgetary and other constraints. (Of course, the “real” problems of industry are often nonlinear; the use of linear programming is sometimes dictated by the computational budget.) The simplex method is an elegant way of arriving at optimal answers. Although theoretically susceptible to exponential delays, the algorithm in practice is highly efficient—which in itself says something interesting about the nature of computation. In terms of widespread use, George Dantzig’s simplex method is among the most successful algorithms of all time.

    3. Krylov subspace iteration methods(1950 Krylov子空间迭代法)

    1950: Magnus Hestenes, Eduard Stiefel, and Cornelius Lanczos, all from the Institute for Numerical Analysis at the National Bureau of Standards, initiate the development of Krylov subspace iteration methods. These algorithms address the seemingly simple task of solving equations of the form Ax = b. The catch, of course, is that A is a huge n x n matrix, so that the algebraic answer x = b/A is not so easy to compute.(Indeed, matrix “division” is not a particularly useful concept.)
    Iterative methods—such as solving equations of the form Kxi + 1 = Kxi + b – Axi with a simpler matrix K that’s ideally “close” to A—lead to the study of Krylov subspaces. Named for the Russian mathematician Nikolai Krylov, Krylov subspaces are spanned by powers of a matrix applied to an initial “remainder” vector r0 = b – Ax0. Lanczos found a nifty way to generate an orthogonal basis for such a subspace when the matrix is symmetric.
    Hestenes and Stiefel proposed an even niftier method, known as the conjugate gradient method, for systems that are both symmetric and positive definite. Over the last 50 years, numerous researchers have improved and extended these algorithms. The current suite includes techniques for non-symmetric systems, with acronyms like GMRES and Bi-CGSTAB. (GMRES and Bi-CGSTAB premiered in SIAM Journal on Scientific and Statistical Computing, in 1986 and 1992, respectively.)

    4. The decompositional approach to matrix computations(1951 矩阵计算的分解方法)
    1951: Alston Householder of Oak Ridge National Laboratory formalizes the decompositional approach to matrix computations.The ability to factor matrices into triangular, diagonal, orthogonal, and other special forms has turned out to be extremely useful. The decompositional approach has enabled software developers to produce flexible and efficient matrix packages. It also facilitates the analysis of rounding errors, one of the big bugbears of numerical linear algebra. (In 1961, James Wilkinson of the National Physical Laboratory in London published a seminal paper in the Journal of the ACM, titled “Error Analysis of Direct Methods of Matrix Inversion,” based on the LU decomposition of a matrix as a product of lower and upper triangular factors.)

    5.The Fortran optimizing compiler(1957 优化的Fortran编译器)
    1957: John Backus leads a team at IBM in developing the Fortran optimizing compiler. The creation of Fortran may rank as the single most important event in the history of computer programming: Finally, scientists (and others) could tell the computer what they wanted it to do, without having to descend into the netherworld of machine code.
    Although modest by modern compiler standards-Fortran I consisted of a mere 23,500 assembly-language instructions—the early compiler was nonetheless capable of surprisingly sophisticated computations. As Backus himself recalls in a recent history of Fortran I, II, and III, published in 1998 in the IEEE Annals of the History of Computing, the compiler “produced code of such efficiency that its output would startle the programmers who studied it.”

    6. The QR algorithm(1959-1961 计算矩阵特征值的QR算法)

    1959–61: J.G.F. Francis of Ferranti Ltd., London, finds a stable method for computing eigenvalues, known as the QR algorithm. Eigenvalues are arguably the most important numbers associated with matrices-and they can be the trickiest to compute. It’s relatively easy to transform a square matrix into a matrix that’s “almost” upper triangular, meaning one with a single extra set of nonzero entries just below the main diagonal. But chipping away those final nonzeros, without launching an avalanche of error, is nontrivial.
    The QR algorithm is just the ticket. Based on the QR decomposition, which writes A as the product of an orthogonal matrix Q and an upper triangular matrix R, this approach iteratively changes Ai = QR into Ai + 1 = RQ, with a few bells and whistles for accelerating convergence to upper triangular form. By the mid-1960s, the QR algorithm had turned once-formidable eigenvalue problems into routine calculations.

    7. Quicksort(1962 快速排序算法)

    1962: Tony Hoare of Elliott Brothers, Ltd., London, presents Quicksort. Putting N things in numerical or alphabetical order is mind-numbingly mundane. The intellectual challenge lies in devising ways of doing so quickly. Hoare’s algorithm uses the age-old recursive strategy of divide and conquer to solve the problem: Pick one element as a “pivot,” separate the rest into piles of “big” and “small” elements (as compared with the pivot), and then repeat this procedure on each pile.
    Although it’s possible to get stuck doing all N(N – 1)/2 comparisons (especially if you use as your pivot the first item on a list that’s already sorted!), Quicksort runs on average with O(N log N) efficiency. Its elegant simplicity has made Quicksort the posterchild of computational complexity.

    8. FFT(1965 快速傅立叶变换)
    1965: James Cooley of the IBM T.J. Watson Research Center and John Tukey of Princeton University and AT&T Bell Laboratories unveil the fast Fourier transform. Easily the most far-reaching algorithm in applied mathematics, the FFT revolutionized signal processing. The underlying idea goes back to Gauss (who needed to calculate orbits of asteroids), but it was the Cooley-Tukey paper that made it clear how easily Fourier transforms can be computed. Like Quicksort, the FFT relies on a divide-and-conquer strategy to reduce an ostensibly O(N2) chore to an O(N log N) frolic. But unlike Quick- sort, the implementation is (at first sight) nonintuitive and less than straightforward. This in itself gave computer science an impetus to investigate the inherent complexity of computational problems and algorithms.

    9. Integer relation detection algorithm(1977 整数关系探测算法)
    1977: Helaman Ferguson and Rodney Forcade of Brigham Young University advance an integer relation detection algorithm.The problem is an old one: Given a bunch of real numbers, say x1, x2, . . . , xn, are there integers a1, a2, . . . , an (not all 0) for which a1x1 + a2x2 + . . . + anxn = 0? For n = 2, the venerable Euclidean algorithm does the job, computing terms in the continued-fraction expansion of x1/x2. If x1/x2 is rational, the expansion terminates and, with proper unraveling, gives the “smallest” integers a1 and a2.If the Euclidean algorithm doesn’t terminate—or if you simply get tired of computing it—then the unraveling procedure at least provides lower bounds on the size of the smallest integer relation. Ferguson and Forcade’s generalization, although much more difficult to implement (and to understand), is also more powerful. Their detection algorithm, for example, has been used to find the precise coefficients of the polynomials satisfied by the third and fourth bifurcation points, B3 = 3.544090 and B4 = 3.564407, of the logistic map. (The latter polynomial is of degree 120; its largest coefficient is 25730.) It has also proved useful in simplifying calculations with Feynman diagrams in quantum field theory.

    10. The fast multipole algorithm(1987 快速多极算法)
    1987: Leslie Greengard and Vladimir Rokhlin of Yale University invent the fast multipole algorithm. This algorithm overcomes one of the biggest headaches of N-body simulations: the fact that accurate calculations of the motions of N particles interacting via gravitational or electrostatic forces (think stars in a galaxy, or atoms in a protein) would seem to require O(N2) computations—one for each pair of particles. The fast multipole algorithm gets by with O(N) computations. It does so by using multipole expansions (net charge or mass, dipole moment, quadrupole, and so forth) to approximate the effects of a distant group of particles on a local group. A hierarchical decomposition of space is used to define ever-larger groups as distances increase.
    One of the distinct advantages of the fast multipole algorithm is that it comes equipped with rigorous error estimates, a feature that many methods lack.

    What new insights and algorithms will the 21st century bring? The complete answer obviously won’t be known for another hundred years. One thing seems certain, however. As Sullivan writes in the introduction to the top-10 list, “The new century is not going to be very restful for us, but it is not going to be dull either!”

    1946 蒙特卡罗方法
         在广场上画一个边长一米的正方形,在正方形内部随意用粉笔画一个不规则的形状,呃,能帮我算算这个不规则图形的面积么?蒙特卡洛(Monte Carlo)方法便是解决这个问题的巧妙方法:随机向该正方形内扔N(N 是一个很大的自然数)个黄豆,随后数数有多少个黄豆在这个不规则几何形状内部,比如说有M个:那么,这个奇怪形状的面积便近似于M/N,N越大,算出来的 值便越精确。

    1947 单纯形法
          单纯形法是由大名鼎鼎的“预测未来”的兰德公司的Grorge Dantzig发明的,它成为线性规划学科的重要基石。所谓线性规划,简单的说,就是给定一组线性(所有变量都是一次幂)约束条件,求一个给定的目标函数的极值。

    1950 Krylov 子空间迭代法
        50年代初的这两个算法都是关于线性代数中的矩阵计算的。Krylov子空间叠代法是用来求解形如Ax=b 的方程,A是一个n*n 的矩阵,当n充分大时,直接计算变得非常困难,而K r y l o v 方法则巧妙地将其变为Kxi+1=Kxi+b-Axi的迭代形式来求解。它将复杂问题化简为阶段性的易于计算的子步骤。

    1951 矩阵计算的分解方法
        1951年由橡树岭国家实验室的AlstonHouseholder 提出的矩阵计算的分解方法,则证明了任何矩阵都可以分解为三角、对角、正交和其他特殊形式的矩阵,该算法的意义使得开发灵活的矩阵计算软件包成为可能。

    1957 优化的Fortran 编译器
         Fortran是第一种能将数学公式转化为计算机程序的高级语言,它的诞生使得科学家们真正开始利用计算机作为计算工具为他们的研究服务,这是计算机应用技术的一个里程碑级别的贡献。

    1959-1961 计算矩阵特征值的QR算法
         又是一个和线性代数有关的算法,计算特征值是矩阵计算的最核心内容之一,传统的求解方案涉及到高次方程求根,当问题规模大的时候十分困难。QR算法把矩阵 分解成一个正交矩阵和前面提到的 Krylov 方法类似,这又是一个迭代算法,它把复杂的高次方程求根问题化简为阶段性的易于计算的子步骤,使得用计算机求解大规模矩阵特征值成为可能。这个算法的作者 是来自英国伦敦的J.G.F. Francis。

    1962 快速排序算法
         不论是ANSI C,C++ STL,还是Java SDK,天下几乎所有的SDK里都能找到它的某种实现版本。快速排序算法最早由Tony Hoare爵士设计,它的基本思想是将待排序列分为两半,左边的一半总是“小的”,右边的一半总是“大的”,这一过程不断递归持续下去,直到整个序列有 序。快速排序的平均时间复杂度仅仅为O(Nlog(N)),相比于普通选择排序和冒泡排序等而言,实在是历史性的创举。

    1965 快速傅立叶变换
         如果要评选对我们的日常生活影响最大的算法,快速傅立叶变换算法应该是当仁不让的总冠军.哪里有数字信号处理,哪里就有快速傅立叶变换。快速傅立叶算法是 离散傅立叶算法(这可是数字信号处理的基石)的一种快速算法,它有 IBM 华生研究院的James Cooley和普林斯顿大学的John Tukey共同提出,其时间复杂度仅为O(Nlog(N));比时间效率更为重要的是,快速傅立叶算法非常容易用硬件实现,因此它在电子技术领域得到极其 广泛的应用。

    1977 整数关系探测算法
         整数关系探测是个古老的问题,其历史甚至可以追溯到欧几里德的时代。具体的说:给定—组实数X1,X2,...,Xn,是否存在不全为零的整数 a1,a2,...an,使得:a1*X1 + a2*X2 + . . . + an*Xn = 0。这一年BrighamYoung大学的Helaman Ferguson 和Rodney Forcade解决了这一问题。至于这个算法的意义嘛,呃,该算法应用于“简化量子场论中的Feynman图的计算”——太深奥的学问!

    1987 快速多极算法
         日历翻到了1987 年,这一年的算法似乎更加玄奥了,耶鲁大学的L e s l i eGreengard和Vladimir Rokhlin提出的快速多极算法用来计算“经由引力或静电力相互作用的N 个粒子运动”的精确计算。

    源自校内!

     
    from: