Programmer

          追逐夢想的人
          隨筆 - 6, 文章 - 0, 評論 - 5, 引用 - 0
          數據加載中……

          2007年4月13日

          部署spring2.56中的例子jpetstore

          部署環境:tomcat6.0.18   jdk5   mysql5.1

          1.   下載  到www.springsource.org/download 中 下載spring-framework-2.5.6.SEC01-with-dependencies
          2.   jpetstores說明(自己翻譯jpetstore中的readme.txt,本人英語不好 ,翻譯不到位請手下留情)
               配備spring管理的中間層和ibatis作為數據訪問策略數據層,與spring的事務 和抽象DAO相結合。能使用本地的JDBC或者JTA 和2個數據庫中的后者一起工作
               使用了相同的數據模型和演示內容來作為jpetstore的原型,可以分別的查看 "WEB-INF/dataAccessContext-local.xml","WEB-INF/dataAccessContext-jta.xml"
               上下文定義的細節。
               提供了相同的用戶界面兩種不同的Web層實現,一個基于spring mvc,一個基于struts1.1,后者與jpetstore關系密切,但是用JSTL重寫作為jsp的實現,
               盡可能的具有可比性。查看"WEB-INF/web.xml", "WEB-INF/petstore-servlet.xml",and "WEB-INF/struts-config.xml" 的細節。
               與原來的jpetstore原型相比,這個實現在內部結構和松耦合方面有了顯著的改善。支持的應用上下文的概念,現在核心就是構建 應用對象(application objects)
               最顯著的改善就是 PetStoreLogic,現在叫做PetStoreFacade,它不再與配置,資源,事務的細節相關
               注意以spring為基礎的web層實現是故意與以struts為基礎的相似并不是打算改進錯誤信息等方面的現狀。jpetstore包含2個不同實現的web層來概括除了不同
               之外在各自程序設計模型的相同點,也闡明不同風格的配置。
               這個版本的jpetstore也展示了spring遠程處理的可選項 如:Hessian, Burlap, RMI, and Web Services via Apache Axis.他們都提供了即插即用通過
               默認的web應用(注意RMI是添加注釋避免與EJB容器沖突)“客戶端”目錄包含了一個通過所有協議調用OoderService輸出的簡單控制行客戶端。
          3.   部署
          • 創建數據庫  先創建數據庫 執行\jpetstore\db\mysql里面 jpetstore-mysql-schema.sql,jpetstore-mysql-dataload.sql 用來建表和導入數據(不同數據庫自己對應查找)
          • 改數據庫配置文件  在\jpetstore\war\WEB-INF  修改jdbc.properties(自己對應自己的設置)
            1 jdbc.driverClassName=com.mysql.jdbc.Driver
            2 jdbc.url=jdbc:mysql://localhost/jpetstore?
            3 jdbc.username=root
            4 jdbc.password=root
            5 
          • web層實現的選擇  在\jpetstore\war\WEB_INF   web.xml代碼
            <servlet-mapping>
                     
            <!--使用spring mvc默認 -->
                
            <servlet-name>petstore</servlet-name>
                    
            <!--使用struts -->
            <!--<servlet-name>action</servlet-name>-->
                
            <url-pattern>*.do</url-pattern>
            </servlet-mapping>
          • 部署 /jpetstore 運行warfile.bat 生成一個文件夾dist 把里面的jpetstore.war復制到 tomcat目錄下的webapps  ,把對應的數據庫驅動放到tomcat\lib下
          • 運行tomcat 打開瀏覽器http://localhost:8080/jpetstore 可以看到jpetstore頁面  have fun!



          posted @ 2010-03-24 13:43 霜の哀傷 閱讀(1787) | 評論 (2)編輯 收藏

          java學習筆記(xml解析)

          最近學習xml,把學習的代碼發上來   希望對新手有用
          這是note.xml
          <?xml version="1.0" encoding="gb2312" ?> 
          <notes>
          <note date="2007-4-12">
          <from>小紅</from> 
          <to>小林</to> 
          <message>周末一起去吃火鍋呀</message> 
          </note>
          </notes>

          這是dom解析xml代碼
          import java.io.File;
          import java.io.FileInputStream;
          import java.io.FileNotFoundException;
          import java.io.IOException;
          import java.io.InputStream;

          import javax.xml.parsers.DocumentBuilder;
          import javax.xml.parsers.DocumentBuilderFactory;
          import javax.xml.parsers.ParserConfigurationException;

          import org.w3c.dom.Document;
          import org.w3c.dom.Element;
          import org.w3c.dom.Node;
          import org.w3c.dom.NodeList;
          import org.xml.sax.SAXException;


          class  DomXMLTest
          {
              
          public static void main(String[] args)
              {   
                  
          try{
                   
          //(1)得到DOM解析器的工廠實例
                  DocumentBuilderFactory factory =DocumentBuilderFactory.newInstance();     
                    
          //(2)從DOM工廠獲得DOM解析器
                  DocumentBuilder  builder=factory.newDocumentBuilder(); 
                  File f
          =new File("note.xml");
                   
          //(3)把要解析的XML文檔轉化為輸入流,以便DOM解析器解析它
                  InputStream  is=new FileInputStream(f);  
                  
          //(4)解析XML文檔的輸入流,得到一個Document
                  Document doc=builder.parse(is);    
                  
          //(5)得到XML文檔的根節點
                  Element  root=doc.getDocumentElement(); 
                   
          //(6)得到節點的子節點
                  NodeList  notes=root.getChildNodes();   

                    
          for(int i=0;i<notes.getLength();i++)
                    {
                         Node note
          =notes.item(i);
                      
          if(note.getNodeType()==Node.ELEMENT_NODE)
                          {  
                              
          //(7)取得節點的屬性值
                              String date =note.getAttributes().getNamedItem("date").getNodeValue(); 
                              System.out.println(date);
                              
          // (8)輪循子節點
                              for(Node node=note.getFirstChild();node!=null;node=node.getNextSibling()) 
                                   {
                                          
          if(node.getNodeType()==Node.ELEMENT_NODE)
                                               {
                                                      
          if(node.getNodeName().equals("from"))
                                                      {
                                                           String from
          =node.getFirstChild().getNodeValue();
                                                           System.out.println(from);
                                                       }
                                                      
          if(node.getNodeName().equals("to"))
                                                       {
                                                            String to
          =node.getFirstChild().getNodeValue();
                                                             System.out.println(to);
                                                       }
                                                       
          if(node.getNodeName().equals("message"))
                                                       {
                                                             String message
          =node.getFirstChild().getNodeValue();
                                                             System.out.println(message);
                                                        }
                                                }
                                     }
                            }

                  }
                  }
                  
          catch(ParserConfigurationException e)
                  {
                      e.printStackTrace();
                  }
                  
          catch(SAXException e)
                  {
                      e.printStackTrace();
                  }
                  
          catch(IOException e)
                  {
                      e.printStackTrace();
                  }
               }                                  
          }

          還有 出現 下面的錯誤  是xml的格式不對 ,我就應為在 <?xml 前面多個空格 就找了好幾天的錯誤
          特別感謝那些幫我找問題的高手,用范偉的話說  謝謝啊
          The processing instruction target matching "[xX][mM][lL]" is not allowed.




          posted @ 2007-04-13 18:08 霜の哀傷 閱讀(445) | 評論 (1)編輯 收藏

          主站蜘蛛池模板: 灌云县| 缙云县| 绥芬河市| 保亭| 南和县| 江孜县| 政和县| 麦盖提县| 莱州市| 西昌市| 吐鲁番市| 长泰县| 中山市| 西和县| 忻州市| 牙克石市| 屏南县| 怀集县| 彭山县| 罗平县| 毕节市| 宜兰市| 驻马店市| 桓仁| 西乡县| 汶上县| 滦平县| 阿坝县| 辽中县| 龙南县| 马公市| 平和县| 咸阳市| 金门县| 兴义市| 丰原市| 沈阳市| 望江县| 汝城县| 丹江口市| 敦煌市|