隨筆-5  評論-0  文章-0  trackbacks-0
            2010年2月10日
          使用動態驗證框架
          動態Form 繼承類 org.apache.struts.validator.DynaValidatorForm
          <form-beans>
                  
          <form-bean name="loginForm"
                      type
          ="org.apache.struts.validator.DynaValidatorForm">
                      
          <form-property name="account" type="java.lang.String" />
                      
          <form-property name="password" type="java.lang.String" />
                  
          </form-bean>

              
          </form-beans>

          如果運行報錯 :
          java.lang.IllegalArgumentException: Resources cannot be null.
          可能的原因是因為在struts-config.xml文件中沒有為驗證框架注冊
          <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
                  
          <set-property property="pathnames"
                      value
          ="/WEB-INF/validator-rules.xml,/WEB-INF/validator.xml" />
              
          </plug-in>


          posted @ 2010-02-10 18:36 心情 閱讀(453) | 評論 (0)編輯 收藏

          配置過濾器 設置字符集為GBK (注:mysql數據庫和JSP頁面都是使用GBK字符集)
              CharFilterToGBK javax.servlet.Filter;

          public class CharFilterToGBK implements Filter {

           
          public void destroy() {
            
          // TODO Auto-generated method stub

           }


           
          public void doFilter(ServletRequest request, ServletResponse response,
             FilterChain filterChain) 
          throws IOException, ServletException {
            request.setCharacterEncoding(
          "GBK");
            response.setCharacterEncoding(
          "GBK");
            filterChain.doFilter(request, response);
           }

          配置web.xml文件 注冊該過濾器
          <filter>
            
          <filter-name>charFilterToGBK</filter-name>
            
          <filter-class>study.filter.CharFilterToGBK</filter-class>
           
          </filter>
           
          <filter-mapping>
               
          <filter-name>charFilterToGBK</filter-name>
               
          <url-pattern>/*</url-pattern>
           
          </filter-mapping>
          posted @ 2010-02-10 09:45 心情 閱讀(520) | 評論 (0)編輯 收藏
          在struts1.x框架中 JSP頁面向一個ActionForm提交表單內容 對于提交一個日期類型的數據的注意事項

          ActonForm表單中對應的屬性 (日期格式) 格式為java.sql.Date 并且JSP頁面中輸入的數據需要為yyyy-MM-dd格式。
          此種方式不能夠錄入時分秒

          posted @ 2010-02-10 09:10 心情 閱讀(640) | 評論 (0)編輯 收藏
          相同點:TimeStamp列的顯示格式與DateTime列相同,格式為yyyy-MM-dd hh:mm:ss。

          不同點:DateTime支持的范圍為'1000-01-01 00:00:00'到'9999-12-31 23:59:59'  
                         TimeStamp值不能早于1970或晚于2037
          posted @ 2010-02-10 01:04 心情 閱讀(236) | 評論 (0)編輯 收藏
          • 編輯mysql的配置文件my.ini,設置字符集為gbk
          [client]

          port
          =3306

          [mysql]

             default-character-set=gbk
          # SERVER SECTION
          ----------------------------------------------------------------------
          #
          # The following options will be read by the MySQL Server. Make sure that
          # you have installed the server correctly (see above) so it reads 
          this 
          # file.
          #
          [mysqld]

          # The TCP
          /IP Port the MySQL Server will listen on
          port
          =3306


          #Path to installation directory. All paths are usually resolved relative to 
          this.
          basedir
          ="D:/Program Files/MySQL/MySQL Server 5.1/"

          #Path to the database root
          datadir
          ="D:/Program Files/MySQL/MySQL Server 5.1/Application Data/Data/"

          # The 
          default character set that will be used when a new schema or table is
          # created and no character set is defined
          default-character-set=gbk

          # The 
          default storage engine that will be used when create new tables when
          default-storage-engine=INNODB
          • 使用MySQL Workbench設計數據庫 ,數據庫和表均使用默認的字符集
          • 在Servlet中轉換字符編碼
          String name = request.getParameter("name");
          name 
          = new String(name.getBytes("ISO-8859-1"));
          • 設置JSP頁面字符集為GBK
          <%@ page language="java" pageEncoding="GBK"%>
          posted @ 2010-02-10 00:52 心情 閱讀(387) | 評論 (0)編輯 收藏
          僅列出標題  
          主站蜘蛛池模板: 历史| 怀安县| 项城市| 威宁| 益阳市| 社旗县| 奈曼旗| 钟山县| 通渭县| 宁阳县| 丹巴县| 睢宁县| 青川县| 黄石市| 汕头市| 栾川县| 钟祥市| 屏山县| 凤冈县| 临颍县| 建平县| 克什克腾旗| 江北区| 三明市| 门源| 保山市| 通许县| 玉门市| 湘潭县| 肥乡县| 昌宁县| 西城区| 新乡县| 武胜县| 靖远县| 沁阳市| 伊川县| 济南市| 桃源县| 松滋市| 宁阳县|