修改myEclipse自帶的tomcat發布端口

          首先到你的MyEclipse文件下去搜索server.xml 這個文件

          修改這個文件里面的一個參數

          <Connector port="8080" protocol="HTTP/1.1"

                         connectionTimeout="20000"

                         redirectPort="8443" />


          2.在Myeclipse中,在(工具欄吧叫做,就是有File Edit 的那一行),選window -> Preferences -> Myeclipse -> Servers -> Integrated Sandbox -> Myeclipse Tomcat 6修改相應端口號

          posted @ 2012-05-29 21:52 youngturk 閱讀(5182) | 評論 (2)編輯 收藏

          request.getParameterMap()得到form頁面所有值

          example:
              
          <@global.dialogBegin title="轉棧申請審批"/>
          <form id="declare_form" method="post" action="${webroot}/delivery/receive!verify.do">    
              
          <input type="hidden" name="id" id="rowId">    
              
          <label>審核結果:</label><br/><input type="radio" id="yard_confirm_flag" name="yardConfirmFlag" value="Y">同意轉棧申請<input type="radio" id="yard_confirm_flag" name="yardConfirmFlag" value="N">拒絕轉棧申請<br/>
              
          <br/><label>審核意見:</label><br/><textarea name="yardConfirmComment" id="yard_confrim_comment" style="width:90%;height:60px;overflow:hidden;">同意轉棧申請,等待海關審核</textarea><br/>
          </form>    
          <@global.dialogEnd button="審批"/>

            
          DeliveryMainIndex.java 

          private String yardConfirmComment ;

          public String getYardConfirmComment() {
            
          return yardConfirmComment;
           }


           
          public void setYardConfirmComment(String yardConfirmComment) {
            
          this.yardConfirmComment = yardConfirmComment;
           }


          DeliveryMainIndex obj = (DeliveryMainIndex)this.bindRequestToBean(DeliveryMainIndex.class);

              public Object bindRequestToBean(Class clazz){
                  Object obj 
          = null ;
                  
          try {
                      obj 
          = clazz.newInstance();            
                      BeanUtils.populate(obj, request.getParameterMap());//獲取ftl所有值,將其轉化成實體bean
                  }
           catch (InstantiationException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
           catch (IllegalAccessException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
           catch (InvocationTargetException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  }

                  
          return obj ;
              }









          posted @ 2012-05-29 09:53 youngturk 閱讀(1830) | 評論 (2)編輯 收藏

          增加表列項 alter table

          alter table test add ( test_column varchar2(20) )
          comment on column test_column is 'test'

          posted @ 2012-05-28 13:54 youngturk 閱讀(219) | 評論 (0)編輯 收藏

          heap,stack的區別

          example:
          Point p1 = new Point(1,2);
          Point p2 = new Point(3,4);

          p2 = p1 ; 此時 是p2指針的內容指向了p1,p1和p2的內容相等,但是p1的地址可能是1000,p2的地址是2000,p1,p2地址內容值都指向同一內容(1,2),此時(1,2)是heap,p2和p1的地址存向stack
          Point p3 = null;
          p3.moveto(1,2)此時報錯,p3沒對象;

          posted @ 2012-05-28 08:45 youngturk 閱讀(209) | 評論 (0)編輯 收藏

          視頻學習的第一個springMVC原創

               摘要: 首先我將所有需要的文件引入: Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->loging.jsp${error}  <body>    <form metho...  閱讀全文

          posted @ 2012-05-26 13:05 youngturk 閱讀(1273) | 評論 (1)編輯 收藏

          Method 類中 invoke方法的調用

          public void invokeActionHandler(ModelAndView mv , HttpServletRequest request) throws Exception{
                  String className 
          = mv.getClassName();
                  String methodName 
          = mv.getMethodName();
                  
          //load class
                  Class controllerClass = cache.loadClass(className);//== Class.forName(className);java反射機制,jvm加載lassName類
                  Class parentControllerClass = cache.loadClass(baseControllerClass);//class org.bluechant.mvc.controller.Controller
                  
          //load method參數1類,創建一個方法為setRequest參數為HttpServletRequest.class的方法與method = clazz.getDeclaredMethod(setRequest, HttpServletRequest.class);與HttpServletRequest的setRequest方法一致的方法.
                  Method setRequest = cache.loadMethod(parentControllerClass, "setRequest"new Class[] { HttpServletRequest.class });    //HttpServletRequest.class,java的反射機制得到自己的類,能夠擁有自己的方法值,(Method setRequest獲取成員函數)
                  Method setModelAndView = cache.loadMethod(parentControllerClass, "setModelAndView"new Class[] { ModelAndView.class });//org.bluechant.mvc.controller.Controller-setModelAndView@6024418  public void org.bluechant.mvc.controller.Controller.setModelAndView(org.bluechant.mvc.controller.ModelAndView)
                  Method targetMethod = cache.loadMethod(controllerClass, methodName, new Class[]{});
                  
          //buiid controller instance and invoke target method以上setRequest,setModelAndView,targetMethod都放在cache(hashMap中)
                  Object instance = controllerClass.newInstance();//加載className類
                  setRequest.invoke(instance, new Object[] { request });//對帶有指定參數的指定對象調用由此 Method 對象表示的基礎方法    
                  setModelAndView.invoke(instance, new Object[] { mv });//instance立即為原型指針
                  targetMethod.invoke(instance, new Object[]{});    
                  
          //調用instance類中targetMethod這個方法,Object[]{}這個作為參數..
                  
          //invoke根據實體獲得方法,添加所要造的參數,就是個找實例的方法克隆工廠,由Method獲得實例模型,由方法鍛造樣子,傳入參數得出想要結果
              }


          方法說明實例:


          }
          class ClassB{
           public ClassB(){
            System.out.println("this is ClassB");
           }

           public Object invokeMehton(Object owner,String methodName,Object[] args) throws Exception{
                            //根據methodName獲得owner里面的方法。args是對應方案參數。
            Class wnerClass=owner.getClass();
            Class[] argsClass=new Class[args.length];
            for(int i=0,j=args.length;i<j;i++){
              argsClass[i] = args[i].getClass();
            }
            Method method = ownerClass.getMethod(methodName, argsClass); 
            return method.invoke(owner, args);
           }
          }

          輸出為
          this is ClassB
          300
          outabccc

          說明c調用Class方法成功。


          import java.lang.reflect.Method;

          public class ClassA {
                  //ClassA里面有add、和StringAdd兩個不同方法。c是ClassB的Object
           ClassB c=new ClassB();
           public void add(Integer param1, Integer param2) {  
            
              System.out.println(param1 + param2);  
             
             }
           public void StringAdd(String abc){
            System.out.println("out"+abc);
           }
           public static void main(String[] args){
            ClassA a=new ClassA();
            try {
             a.c.invokeMehton(a, "add",new Object[] {new Integer(100),new Integer(200)});//反射調用方法add
             a.c.invokeMehton(a, "StringAdd",new Object[] {new String("abccc")});//反射調用方法StringAdd
            } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
            
            
            
           }


           



          posted @ 2012-05-24 18:54 youngturk 閱讀(608) | 評論 (0)編輯 收藏

          java連接數據庫(第一步)

          需要聯系的幾個文件:DaosupportController,extents Controller,BeanFactory,CoreDispatcherController,appcontext.xml.
          有web.xml中
          <servlet>
                  <!-- servlet獲得控制文件Class的名字,類名 -->
            <servlet-name>smvcCoreDispatcher</servlet-name>
            <servlet-class>org.bluechant.mvc.core.CoreDispatcherController</servlet-class>
          .....
          </servlet>
          有CoreDispatcherController開始-->

          public void invokeActionHandler(ModelAndView mv , HttpServletRequest request) throws Exception{
                  String className 
          = mv.getClassName();
                  String methodName 
          = mv.getMethodName();
                  
          //load class
                  Class controllerClass = cache.loadClass(className);//== Class.forName(className);java反射機制,jvm加載lassName類
                  Class parentControllerClass = cache.loadClass(baseControllerClass);//class org.bluechant.mvc.controller.Controller
                  
          //load method參數1類,創建一個方法為setRequest參數為HttpServletRequest.class的方法與method = clazz.getDeclaredMethod(setRequest, HttpServletRequest.class);與HttpServletRequest的setRequest方法一致的方法.
                  Method setRequest = cache.loadMethod(parentControllerClass, "setRequest"new Class[] { HttpServletRequest.class });    //HttpServletRequest.class,java的反射機制得到自己的類,能夠擁有自己的方法值,(Method setRequest獲取成員函數)
                  Method setModelAndView = cache.loadMethod(parentControllerClass, "setModelAndView"new Class[] { ModelAndView.class });//org.bluechant.mvc.controller.Controller-setModelAndView@6024418  public void org.bluechant.mvc.controller.Controller.setModelAndView(org.bluechant.mvc.controller.ModelAndView)
                  Method targetMethod = cache.loadMethod(controllerClass, methodName, new Class[]{});
                  
          //buiid controller instance and invoke target method以上setRequest,setModelAndView,targetMethod都放在cache(hashMap中)
                  Object instance = controllerClass.newInstance();//加載className類;//此方法引入數據庫連接 
                  //以上剛進入頁面的時候instance調用三個類初始化,分別是繼承關系DaosupportController ,controller,和BeanFactory
                  /*--->>>其中DaoSupportController類中protected ObjectDao dao = (ObjectDao)BeanFactory.getBean("objectDao");
                  --->>>調用:getBean 方法public class BeanFactory {
                      public static ApplicationContext context = new ClassPathXmlApplicationContext("appcontext.xml") ;//此方法引入數據庫連接                                        
                      public static Object getBean(String beanId) {
                          return context.getBean(beanId);
                      }
                  }
          */

                  setRequest.invoke(instance, 
          new Object[] { request });//對帶有指定參數的指定對象調用由此 Method 對象表示的基礎方法    
                  setModelAndView.invoke(instance, new Object[] { mv });//instance立即為原型指針
          //        --->>>執行指定的targetMethod方法實則為AccountController的login()登陸方法此時開始調用數據庫
                  targetMethod.invoke(instance, new Object[]{});    
                  
          //調用instance類中targetMethod這個方法,Object[]{}這個作為參數..
                  
          //invoke根據實體獲得方法,添加所要造的參數,就是個找實例的方法克隆工廠,由Method獲得實例模型,由方法鍛造樣子,傳入參數得出想要結果
              }

          }



          posted @ 2012-05-24 16:49 youngturk 閱讀(201) | 評論 (0)編輯 收藏

          java下Class.forName的作用是什么,為什么要使用它

          Class.forName(xxx.xx.xx) 返回的是一個類

          首先你要明白在java里面任何class都要裝載在虛擬機上才能運行。這句話就是裝載類用的(和new 不一樣,要分清楚)。 

          至于什么時候用,你可以考慮一下這個問題,給你一個字符串變量,它代表一個類的包名和類名,你怎么實例化它?只有你提到的這個方法了,不過要再加一點。 
          A a = (A)Class.forName("pacage.A").newInstance(); 
          這和你 
          A a = new A(); 
          是一樣的效果。 

          關于補充的問題 
          答案是肯定的,jvm會執行靜態代碼段,你要記住一個概念,靜態代碼是和class綁定的,class裝載成功就表示執行了你的靜態代碼了。而且以后不會再走這段靜態代碼了。

          Class.forName(xxx.xx.xx) 返回的是一個類 
          Class.forName(xxx.xx.xx);的作用是要求JVM查找并加載指定的類,也就是說JVM會執行該類的靜態代碼段

          動態加載和創建Class 對象,比如想根據用戶輸入的字符串來創建對象 
          String str = 用戶輸入的字符串 
          Class t = Class.forName(str); 
          t.newInstance();

           在初始化一個類,生成一個實例的時候,newInstance()方法和new關鍵字除了一個是方法,一個是關鍵字外,最主要有什么區別?它們的區別在于創建對象的方式不一樣,前者是使用類加載機制,后者是創建一個新類。那么為什么會有兩種創建對象方式?這主要考慮到軟件的可伸縮、可擴展和可重用等軟件設計思想。 

          Java中工廠模式經常使用newInstance()方法來創建對象,因此從為什么要使用工廠模式上可以找到具體答案。 例如: 
          class c = Class.forName(“Example”); 
          factory = (ExampleInterface)c.newInstance(); 

          其中ExampleInterface是Example的接口,可以寫成如下形式: 
          String className = "Example"; 
          class c = Class.forName(className); 
          factory = (ExampleInterface)c.newInstance(); 

          進一步可以寫成如下形式: 
          String className = readfromXMlConfig;//從xml 配置文件中獲得字符串 
          class c = Class.forName(className); 
          factory = (ExampleInterface)c.newInstance(); 

          上面代碼已經不存在Example的類名稱,它的優點是,無論Example類怎么變化,上述代碼不變,甚至可以更換Example的兄弟類Example2 , Example3 , Example4……,只要他們繼承ExampleInterface就可以。 

          從JVM的角度看,我們使用關鍵字new創建一個類的時候,這個類可以沒有被加載。但是使用newInstance()方法的時候,就必須保證:1、這個類已經加載;2、這個類已經連接了。而完成上面兩個步驟的正是Class的靜態方法forName()所完成的,這個靜態方法調用了啟動類加載器,即加載 java API的那個加載器。 

          現在可以看出,newInstance()實際上是把new這個方式分解為兩步,即首先調用Class加載方法加載某個類,然后實例化。 這樣分步的好處是顯而易見的。我們可以在調用class的靜態加載方法forName時獲得更好的靈活性,提供給了一種降耦的手段。 

          最后用最簡單的描述來區分new關鍵字和newInstance()方法的區別: 
          newInstance: 弱類型。低效率。只能調用無參構造。 
          new: 強類型。相對高效。能調用任何public構造。

          posted @ 2012-05-24 14:32 youngturk 閱讀(210) | 評論 (0)編輯 收藏

          web.xml中 filter解析

          AdminFilter.java:
          package org.bluechant.mvc.filter;

          import java.io.IOException;

          import javax.servlet.Filter;
          import javax.servlet.FilterChain;
          import javax.servlet.FilterConfig;
          import javax.servlet.ServletException;
          import javax.servlet.ServletRequest;
          import javax.servlet.ServletResponse;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
          import javax.servlet.http.HttpSession;

          import org.bluechant.mvc.core.GlobalSources;

          /**
           * 
          @author CHAOS
           * @date 2012-02-28 12:49
           * filter for check wheather user already login in ,
           * if not , send redirect to the login page 
           * if already login , forward user's request to the target request URL
           
          */

          public class AdminFilter implements Filter 
              
              
          private String loginPage ;
              
              
          private String loginAction ;
              
              
          private String userLoginTag ;
              
          //FilterConfig可用于訪問Filter的配置信息
              private FilterConfig config;

              
          //執行過濾的核心方法
              public void doFilter(ServletRequest req, ServletResponse res,
                      FilterChain chain) 
          throws IOException, ServletException {
                  
                  HttpServletRequest request 
          = (HttpServletRequest) req;
                  HttpServletResponse  response 
          = (HttpServletResponse )res;
                  HttpSession session 
          = request.getSession(true);

                  
          //獲取客戶請求的頁面
                  String urlPath = request.getServletPath();
                  
          //如果session范圍的user為null,即表明沒有登錄
                  
          //且用戶請求的既不是登錄頁面,也不是處理登錄的頁面if( session.getAttribute("user") == null

                  
          boolean flag = needNotFilter(urlPath);
                  
          //不需要進行攔截的頁面
                  if(!flag){
                      Object obj 
          = session.getAttribute(userLoginTag);
                      System.out.println(
          "the session userLoginTag value is :"+obj);
                      
          if(obj!=null){
                          flag 
          = true ;
                      }

                  }

                  
          if(flag){
                      chain.doFilter(req, res);
                  }
          else{
                      
          //攔截不通過的時候跳轉到的目標//forward到登錄頁面
                      response.sendRedirect(request.getContextPath()+loginPage);
                  }

              }

              
          //只有在”/login.html“ || “/account!login.do” 情況下才進行攔截通過,否則攔截不通過跳到登陸頁面
              private boolean needNotFilter(String urlPath){
                  
          if(urlPath.endsWith(loginPage) || urlPath.endsWith(loginAction)){
                      
          return true ;
                  }

                  
          return false ;
              }


              
          /**
               * init params
               
          */

              
          public void init(FilterConfig config) throws ServletException {
                  loginPage 
          = config.getInitParameter("loginPage");
                  loginAction 
          = config.getInitParameter("loginAction");
                  userLoginTag 
          = config.getInitParameter("userLoginTag");
                  System.out.println(
          "the loginPage value is :"+loginPage);
                  System.out.println(
          "the loginAction value is :"+loginAction);
                  System.out.println(
          "the userLoginTag value is :"+userLoginTag);
                  
          this.config = config;
                  
          //以前頁面登陸的時候session進行設置HttpSession session = request.getSession(true);
                  
          //session.setAttribute(GlobalSources.user_login_tag, user);
                  GlobalSources.user_login_tag = userLoginTag ;//session放到GlobalSources,bean里,
          用GlobalSources.user_login_tag獲得

              }


              
          public void destroy(){
                  
                  
          this.config = null;
              }


          }


          web.xml中對應filter文件:
           <filter>
                <filter-name>adminFilter</filter-name>
                <filter-class>org.bluechant.mvc.filter.AdminFilter</filter-class>
                    <init-param>
                         <param-name>loginAction</param-name>
                         <param-value>/account!login.do</param-value>
                    </init-param>
                    <init-param>
                         <param-name>loginPage</param-name>
                         <param-value>/login.html</param-value>
                    </init-param>
                    <init-param>
                         <param-name>userLoginTag</param-name>
                         <param-value>account_login_check</param-value>
                    </init-param>  
           </filter>
           
           <filter>
                    <filter-name>userSourceFilter</filter-name>
                    <filter-class>org.bluechant.mvc.filter.AccountRoleFilter</filter-class>
           </filter>
           
           <filter-mapping>
                    <filter-name>adminFilter</filter-name>
                    <url-pattern>*.do</url-pattern><!-- 表明凡是訪問跳轉*.do形式的跳轉,都要運行名字為adminFilter的過濾器 -->
           </filter-mapping>
           
           <filter-mapping>
                    <filter-name>userSourceFilter</filter-name>
                    <url-pattern>*.do</url-pattern>
           </filter-mapping>

          posted @ 2012-05-24 10:40 youngturk 閱讀(900) | 評論 (0)編輯 收藏

          web.xml filter聲明過濾器

          過濾器可截取和修改進入一個servlet或JSP頁面的請求或從一個servlet或JSP頁面發出的相應。在執行一個 servlet或JSP頁面之前,必須執行第一個相關的過濾器的doFilter方法。在該過濾器對其FilterChain對象調用doFilter 時,執行鏈中的下一個過濾器。如果沒有其他過濾器,servlet或JSP頁面被執行。過濾器具有對到來的ServletRequest對象的全部訪問權,因此,它們可以查看客戶機名、查找到來的cookie等。為了訪問servlet或JSP頁面的輸出,過濾器可將響應對象包裹在一個替身對象(stand-in object)中,比方說把輸出累加到一個緩沖區。在調用FilterChain對象的doFilter方法之后,過濾器可檢查緩沖區,如有必要,就對它進行修改,然后傳送到客戶機。
              <filter>
                  
          <filter-name>adminFilter</filter-name>
                  
          <filter-class>org.bluechant.mvc.filter.AdminFilter</filter-class><!--服務器部署的時候,adminFilter開始加載初始化-->
                  
          <init-param>
                      
          <param-name>loginAction</param-name>
                      
          <param-value>/account!login.do</param-value>
                  
          </init-param>
                  
          <init-param>
                      
          <param-name>loginPage</param-name>
                      
          <param-value>/login.html</param-value>
                  
          </init-param>
                  
          <init-param>
                      
          <param-name>userLoginTag</param-name>
                      
          <param-value>account_login_check</param-value>
                  
          </init-param>        
              
          </filter>
              
              
          <filter>
                  
          <filter-name>userSourceFilter</filter-name>
                  
          <filter-class>org.bluechant.mvc.filter.AccountRoleFilter</filter-class>
              
          </filter>
              
              
          <filter-mapping>
                  
          <filter-name>adminFilter</filter-name>
                  
          <url-pattern>*.do</url-pattern><!-- 表明凡是訪問跳轉*.do形式的跳轉,都要運行名字為adminFilter的過濾器 -->
              
          </filter-mapping>
              
              
          <filter-mapping>
                  
          <filter-name>userSourceFilter</filter-name>
                  
          <url-pattern>*.do</url-pattern>
              
          </filter-mapping>
              <!--接著順序加載servlet被初始化-->

          posted @ 2012-05-23 22:31 youngturk 閱讀(649) | 評論 (1)編輯 收藏

          僅列出標題
          共33頁: First 上一頁 13 14 15 16 17 18 19 20 21 下一頁 Last 
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          公告

          this year :
          1 jQuery
          2 freemarker
          3 框架結構
          4 口語英語

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          相冊

          EJB學習

          Flex學習

          learn English

          oracle

          spring MVC web service

          SQL

          Struts

          生活保健

          解析文件

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 巫溪县| 天祝| 屏东县| 浏阳市| 综艺| 兴海县| 绍兴市| 商南县| 新安县| 上犹县| 河津市| 梅州市| 玉龙| 苏尼特右旗| 桓仁| 手游| 门源| 灵武市| 黑龙江省| 罗田县| 五大连池市| 平阴县| 日照市| 柘城县| 建瓯市| 黄浦区| 大荔县| 芦山县| 温州市| 呼图壁县| 云龙县| 伊吾县| 遂川县| 叶城县| 瑞安市| 边坝县| 财经| 朝阳县| 江孜县| 房产| 密山市|