溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請(qǐng)您在轉(zhuǎn)載時(shí)注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          雪山飛鵠

          溫馨提示:您的每一次轉(zhuǎn)載,體現(xiàn)了我寫此文的意義!!!煩請(qǐng)您在轉(zhuǎn)載時(shí)注明出處http://www.aygfsteel.com/sxyx2008/謝謝合作!!!

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            215 Posts :: 1 Stories :: 674 Comments :: 0 Trackbacks

          公告

          Locations of visitors to this page

          常用鏈接

          留言簿(18)

          隨筆分類(222)

          隨筆檔案(214)

          文章檔案(1)

          收藏夾(67)

          我的鏈接

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          #

          本文轉(zhuǎn)自http://xphnet.hpsbhq.com/paperdetail.aspx?paperid=31

                1、功能講解:
            innerHTML 設(shè)置或獲取位于對(duì)象起始和結(jié)束標(biāo)簽內(nèi)的 HTML
            outerHTML 設(shè)置或獲取對(duì)象及其內(nèi)容的 HTML 形式
            innerText 設(shè)置或獲取位于對(duì)象起始和結(jié)束標(biāo)簽內(nèi)的文本
            outerText 設(shè)置(包括標(biāo)簽)或獲取(不包括標(biāo)簽)對(duì)象的文本
            2、示例代碼(可直接復(fù)制后轉(zhuǎn)存執(zhí)行):
            <html>
            <head>
            <title>Demo</title>
            <style><!--
            body {font-family:"宋體";color="blue";font-size="9pt"}
            --> </style>
            <script language="JavaScript">
            //.innerHTML
            function innerHTMLDemo()
            {
             test_id1.innerHTML="<i><u>設(shè)置或獲取位于對(duì)象起始和結(jié)束標(biāo)簽內(nèi)的 HTML.</u></i>";
            }
            //.innerText
            function innerTextDemo()
            {
             test_id2.innerText="<i><u>設(shè)置或獲取位于對(duì)象起始和結(jié)束標(biāo)簽內(nèi)的文本.</u></i>";
            }
            //.outerHTML
            function outerHTMLDemo()
            {
             test_id3.outerHTML="<i><u>設(shè)置或獲取對(duì)象及其內(nèi)容的 HTML 形式.</u></i>";
            }
            //.outerText
            function outerTextDemo()
            {
             test_id4.outerText="<i><u>設(shè)置(包括標(biāo)簽)或獲取(不包括標(biāo)簽)對(duì)象的文本.</u></i>";
            }
            </script>
            </head>
            <body>
            <ul>
            <li id="test_id1" onclick="innerHTMLDemo()">innerHTML效果.</li>
            <li id="test_id2" onclick="innerTextDemo()">innerText效果.</li>
            <li id="test_id3" onclick="outerHTMLDemo()">outerHTML效果.</li>
            <li id="test_id4" onclick="outerTextDemo()">outerText效果.</li>
            </ul>
            </body>
            </html>
            3、不同之處:
            簡(jiǎn)單的說(shuō)innerHTML和outerHTML、innerText與outerText的不同之處在于:
            1)、innerHTML與outerHTML在設(shè)置對(duì)象的內(nèi)容時(shí)包含的HTML會(huì)被解析,而innerText與outerText則不會(huì)。
            2)、在設(shè)置時(shí),innerHTML與innerText僅設(shè)置標(biāo)簽內(nèi)的文本,而outerHTML與outerText設(shè)置包括標(biāo)簽在內(nèi)的文本。

          posted @ 2010-11-03 10:38 雪山飛鵠 閱讀(2118) | 評(píng)論 (2)編輯 收藏

          點(diǎn)我下載工程代碼
          由于項(xiàng)目需求,在處理文件上傳時(shí)需要使用到文件的異步上傳。這里使用Jquery Ajax File Uploader這個(gè)組件下載地址http://www.phpletter.com/download_project_version.php?version_id=6
          服務(wù)器端采用struts2來(lái)處理文件上傳。
          所需環(huán)境:
          jquery.js
          ajaxfileupload.js
          struts2所依賴的jar包
          及struts2-json-plugin-2.1.8.1.jar
          編寫文件上傳的Action

          package com.ajaxfile.action;

          import java.io.File;
          import java.io.FileInputStream;
          import java.io.FileOutputStream;

          import org.apache.struts2.ServletActionContext;

          import com.opensymphony.xwork2.ActionSupport;

          @SuppressWarnings(
          "serial")
          public class FileAction extends ActionSupport {

              
          private File file;
              
          private String fileFileName;
              
          private String fileFileContentType;

              
          private String message = "你已成功上傳文件";
              
              
          public String getMessage() {
                  
          return message;
              }

              
          public void setMessage(String message) {
                  
          this.message = message;
              }

              
          public File getFile() {
                  
          return file;
              }

              
          public void setFile(File file) {
                  
          this.file = file;
              }

              
          public String getFileFileName() {
                  
          return fileFileName;
              }

              
          public void setFileFileName(String fileFileName) {
                  
          this.fileFileName = fileFileName;
              }

              
          public String getFileFileContentType() {
                  
          return fileFileContentType;
              }

              
          public void setFileFileContentType(String fileFileContentType) {
                  
          this.fileFileContentType = fileFileContentType;
              }

              @SuppressWarnings(
          "deprecation")
              @Override
              
          public String execute() throws Exception {
                  
                  String path 
          = ServletActionContext.getRequest().getRealPath("/upload");

                  
          try {
                      File f 
          = this.getFile();
                      
          if(this.getFileFileName().endsWith(".exe")){
                          message
          ="對(duì)不起,你上傳的文件格式不允許!!!";
                          
          return ERROR;
                      }
                      FileInputStream inputStream 
          = new FileInputStream(f);
                      FileOutputStream outputStream 
          = new FileOutputStream(path + "/"+ this.getFileFileName());
                      
          byte[] buf = new byte[1024];
                      
          int length = 0;
                      
          while ((length = inputStream.read(buf)) != -1) {
                          outputStream.write(buf, 
          0, length);
                      }
                      inputStream.close();
                      outputStream.flush();
                  } 
          catch (Exception e) {
                      e.printStackTrace();
                      message 
          = "對(duì)不起,文件上傳失敗了!!!!";
                  }
                  
          return SUCCESS;
              }

          }
          struts.xml
          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
          <struts>
              
          <package name="struts2" extends="json-default">
                  
          <action name="fileUploadAction" class="com.ajaxfile.action.FileAction">
                      
          <result type="json" name="success">
                          
          <param name="contentType">
                              text/html
                          
          </param>
                      
          </result>
                      
          <result type="json" name="error">
                          
          <param name="contentType">
                              text/html
                          
          </param>
                      
          </result>
                  
          </action>
              
          </package>
          </struts>    
          注意結(jié)合Action觀察struts.xml中result的配置。 

          contentType參數(shù)是一定要有的,否則瀏覽器總是提示將返回的JSON結(jié)果另存為文件,不會(huì)交給ajaxfileupload處理。這是因?yàn)閟truts2 JSON Plugin默認(rèn)的contentType為application/json,而ajaxfileupload則要求為text/html。
          文件上傳的jsp頁(yè)面

          <%@ page language="java" contentType="text/html; charset=UTF-8"
              pageEncoding
          ="UTF-8"%>
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
          <html>
              
          <head>
                  
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                  
          <title>Insert title here</title>
                  
          <script type="text/javascript" src="js/jquery.js"></script>
                  
          <script type="text/javascript" src="js/ajaxfileupload.js"></script>
                  
          <script type="text/javascript">
              
          function ajaxFileUpload()
              {
                  
                  $(
          "#loading")
                  .ajaxStart(
          function(){
                      $(
          this).show();
                  })
          //開始上傳文件時(shí)顯示一個(gè)圖片
                  .ajaxComplete(function(){
                      $(
          this).hide();
                  });
          //文件上傳完成將圖片隱藏起來(lái)
                  
                  $.ajaxFileUpload
                  (
                      {
                          url:'fileUploadAction.action',
          //用于文件上傳的服務(wù)器端請(qǐng)求地址
                          secureuri:false,//一般設(shè)置為false
                          fileElementId:'file',//文件上傳空間的id屬性  <input type="file" id="file" name="file" />
                          dataType: 'json',//返回值類型 一般設(shè)置為json
                          success: function (data, status)  //服務(wù)器成功響應(yīng)處理函數(shù)
                          {
                              alert(data.message);
          //從服務(wù)器返回的json中取出message中的數(shù)據(jù),其中message為在struts2中action中定義的成員變量
                              
                              
          if(typeof(data.error) != 'undefined')
                              {
                                  
          if(data.error != '')
                                  {
                                      alert(data.error);
                                  }
          else
                                  {
                                      alert(data.message);
                                  }
                              }
                          },
                          error: 
          function (data, status, e)//服務(wù)器響應(yīng)失敗處理函數(shù)
                          {
                              alert(e);
                          }
                      }
                  )
                  
                  
          return false;

              }
              
          </script>
              
          </head>
              
          <body>
                  
          <img src="loading.gif" id="loading" style="display: none;">
                  
          <input type="file" id="file" name="file" />
                  
          <br />
                  
          <input type="button" value="上傳" onclick="return ajaxFileUpload();">
              
          </body>
          </html>

           注意觀察<body>中的代碼,并沒有form表單。只是在按鈕點(diǎn)擊的時(shí)候觸發(fā)ajaxFileUpload()方法。需要注意的是js文件引入的先后順序,ajaxfileupload.js依賴于jquery因此你知道的。
          點(diǎn)我下載工程代碼

          posted @ 2010-11-02 16:57 雪山飛鵠 閱讀(60654) | 評(píng)論 (11)編輯 收藏

               摘要: 點(diǎn)我下載工程代碼 實(shí)體類 Department package com.sj.bean; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.E...  閱讀全文
          posted @ 2010-11-02 10:47 雪山飛鵠 閱讀(20196) | 評(píng)論 (7)編輯 收藏

          環(huán)境

          UserDAO
          package com.spring.dao;

          import org.springframework.stereotype.Component;

          @Component(
          "userDAO")
          public class UserDao {

              
          public void say() {
                  System.out.println(
          "say method is called");
              }

              
          public void smile() {
                  System.out.println(
          "smile method is called");
              }
              
              
          public void cry() {
                  System.out.println(
          "cry method is called");
              }
              
              
          public void jump() {
                  System.out.println(
          "jump method is called");
              }
          }
          不做過(guò)多解釋,不清楚的可參考上篇Spring AOP之HelloWorld xml配置
          UserService
          package com.spring.service;

          import javax.annotation.Resource;

          import org.springframework.stereotype.Component;

          import com.spring.dao.UserDao;

          @Component(
          "userService")
          public class UserService {
              
              @Resource(name
          ="userDAO")
              
          private UserDao dao;

              
          public UserDao getDao() {
                  
          return dao;
              }

              
          public void setDao(UserDao dao) {
                  
          this.dao = dao;
              }
              
              
          public void say() {
                  dao.say();
              }

              
          public void smile() {
                  dao.smile();
              }
              
              
          public void cry() {
                  dao.cry();
              }
              
              
          public void jump() {
                  dao.jump();
              }
          }
          Aop攔截類
          package com.spring.aop;

          import org.aspectj.lang.annotation.After;
          import org.aspectj.lang.annotation.AfterThrowing;
          import org.aspectj.lang.annotation.Aspect;
          import org.aspectj.lang.annotation.Before;
          import org.springframework.stereotype.Component;

          @Component(
          "logIntercepter")
          @Aspect
          public class LogIntercepter {
              
              
          /*public void before(){
                  System.out.println("----------before-------------");
              }
              
              public void after(){
                  System.out.println("----------after-------------");
              }
              
              public void exception(){
                  System.out.println("----------exception-------------");
              }
              
              public void around(){
                  System.out.println("----------exception-------------");
              }
          */
              
              @Before(
          "execution(* com.spring.service..*.*(..))")
              
          public void before(){
                  System.out.println(
          "----------before-------------");
              }
              
              @After(
          "execution(* com.spring.service..*.*(..))")
              
          public void after(){
                  System.out.println(
          "----------after-------------");
              }
              
              @AfterThrowing(
          "execution(* com.spring.service..*.*(..))")
              
          public void exception(){
                  System.out.println(
          "----------exception-------------");
              }
              
              
          /*@Around("execution(* com.spring.service..*.*(..))")
              public void around(){
                  System.out.println("----------exception-------------");
              }
          */
              

              
              
          }
          注意觀察
          此類使用了@Aspect注解,你需要在spring配置文件中使用<aop:aspectj-autoproxy/>標(biāo)簽開啟注解功能
          接下來(lái)依次定義了一系列方法before、after、exception、around依次標(biāo)注注解為@Before("execution(* com.spring.service..*.*(..))") 、@After("execution(* com.spring.service..*.*(..))")、@AfterThrowing("execution(* com.spring.service..*.*(..))")、@Around("execution(* com.spring.service..*.*(..))") ,分別為spring aop 的前置通知、后置通知、異常通知、環(huán)繞通知,當(dāng)進(jìn)入com.spring.service包或子包下的所有方法時(shí)他們都會(huì)起作用,其中異常通知,只有在該方法出現(xiàn)異常時(shí)才會(huì)調(diào)用
          applicationContext.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:p
          ="http://www.springframework.org/schema/p"
              xmlns:context
          ="http://www.springframework.org/schema/context"
              xmlns:aop
          ="http://www.springframework.org/schema/aop"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/context 
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/aop
              http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
          >
              
          <context:annotation-config/>
              
          <context:component-scan base-package="com.spring.*"/>
              
          <aop:aspectj-autoproxy/>
              
              
          <!-- 
                  <aop:config>
                      <aop:aspect id="aspect" ref="logIntercepter">
                          <aop:pointcut expression="execution(* com.spring.service..*(..))" id="pointCut"/>
                          <aop:before method="before" pointcut-ref="pointCut"/>
                          <aop:after method="after" pointcut-ref="pointCut"/>
                          <aop:after-throwing method="exception" pointcut-ref="pointCut"/>
                              <aop:around method="around" pointcut-ref="pointCut"/>
                      </aop:aspect>
                  </aop:config>
              
          -->
                  
          </beans>
          內(nèi)容很簡(jiǎn)單
          就這三行
          <context:annotation-config/>
          <context:component-scan base-package="com.spring.*"/>
          <aop:aspectj-autoproxy/>
          其中注視部分為xml配置部分的代碼
          單元測(cè)試
          package com.spring.test;

          import javax.annotation.Resource;

          import org.junit.Test;
          import org.springframework.test.context.ContextConfiguration;
          import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

          import com.spring.service.UserService;

          @ContextConfiguration(locations
          ="classpath:applicationContext.xml")
          public class SpringTest extends AbstractJUnit4SpringContextTests {

              @Resource(name
          ="userService")
              
          private UserService userService;
              
              @Test
              
          public void test1(){
                  userService.say();
                  System.out.println();
                  userService.smile();
                  System.out.println();
                  userService.cry();
              }
              
          }
          運(yùn)行結(jié)果

          ----------before-------------
          say method is called
          ----------after-------------

          ----------before-------------
          smile method is called
          ----------after-------------

          ----------before-------------
          cry method is called
          ----------after-------------

          點(diǎn)我下載工程代碼

          posted @ 2010-10-29 11:11 雪山飛鵠 閱讀(2084) | 評(píng)論 (0)編輯 收藏

          所需jar包

          編寫dao
          package com.spring.dao;

          import org.springframework.stereotype.Component;

          @Component(
          "userDAO")
          public class UserDao {

              
          public void say() {
                  System.out.println(
          "say method is called");
              }

              
          public void smile() {
                  System.out.println(
          "smile method is called");
              }
              
              
          public void cry() {
                  System.out.println(
          "cry method is called");
              }
              
              
          public void jump() {
                  System.out.println(
          "jump method is called");
              }
          }
          注意觀察包名。@Component("userDAO")等價(jià)于在spring配置文件中定義一個(gè)<bean id="userDAO"/>
          編寫Service
          package com.spring.service;

          import javax.annotation.Resource;

          import org.springframework.stereotype.Component;

          import com.spring.dao.UserDao;

          @Component(
          "userService")
          public class UserService {
              
              @Resource(name
          ="userDAO")
              
          private UserDao dao;

              
          public UserDao getDao() {
                  
          return dao;
              }

              
          public void setDao(UserDao dao) {
                  
          this.dao = dao;
              }
              
              
          public void say() {
                  dao.say();
              }

              
          public void smile() {
                  dao.smile();
              }
              
              
          public void cry() {
                  dao.cry();
              }
              
              
          public void jump() {
                  dao.jump();
              }
          }
          注意觀察包名。@Component("userService")等價(jià)于在spring配置文件中定義一個(gè)<bean id="userService"/> @Resource(name="userDAO")將userDA注入進(jìn)來(lái)
          寫一個(gè)攔截器的類
          package com.spring.aop;

          import org.springframework.stereotype.Component;

          @Component(
          "logIntercepter")
          public class LogIntercepter {
              
              
          public void before(){
                  System.out.println(
          "----------before-------------");
              }
              
              
          public void after(){
                  System.out.println(
          "----------after-------------");
              }
              
              
          public void exception(){
                  System.out.println(
          "----------exception-------------");
              }
              
              
          public void around(){
                  System.out.println(
          "----------exception-------------");
              }
          }
          注意觀察包名。@Component("logIntercepter")等價(jià)于在spring配置文件中定義一個(gè)<bean id="logIntercepter"/>
          applicationContext.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance" 
              xmlns:p
          ="http://www.springframework.org/schema/p"
              xmlns:context
          ="http://www.springframework.org/schema/context"
              xmlns:aop
          ="http://www.springframework.org/schema/aop"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
              http://www.springframework.org/schema/context 
              http://www.springframework.org/schema/context/spring-context-3.0.xsd
              http://www.springframework.org/schema/aop
              http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
          >
              
          <context:annotation-config/>
              
          <context:component-scan base-package="com.spring.*"/>
                  
          <aop:config>
                      
          <aop:aspect id="aspect" ref="logIntercepter">
                          
          <aop:pointcut expression="execution(* com.spring.service..*(..))" id="pointCut"/>
                          
          <aop:before method="before" pointcut-ref="pointCut"/>
                          
          <aop:after method="after" pointcut-ref="pointCut"/>
                          
          <aop:after-throwing method="exception" pointcut-ref="pointCut"/>
                          
          <!-- 
                              <aop:around method="around" pointcut-ref="pointCut"/>
                           
          -->
                      
          </aop:aspect>
                  
          </aop:config>
          </beans>
          <context:annotation-config/>
           <context:component-scan base-package="com.spring.*"/>
          兩行為開啟spring的注解配置
          <aop:aspect id="aspect" ref="logIntercepter"> 引入具體的AOP操作類
          <aop:pointcut expression="execution(* com.spring.service..*(..))" id="pointCut"/>聲明一個(gè)切入點(diǎn),注意execution表達(dá)式的寫法
          <aop:before method="before" pointcut-ref="pointCut"/> aop前置通知
          <aop:after method="after" pointcut-ref="pointCut"/> aop后置通知,
          <aop:after-throwing method="exception" pointcut-ref="pointCut"/> aop異常通知
          以上結(jié)合起來(lái)意思就是在調(diào)用com.spring.service包或子包下的所有方法之前或之后或拋出異常時(shí)依次調(diào)用id為logIntercepter的類中的before after exception方法
          測(cè)試用例
          package com.spring.test;

          import javax.annotation.Resource;

          import org.junit.Test;
          import org.springframework.test.context.ContextConfiguration;
          import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

          import com.spring.service.UserService;

          @ContextConfiguration(locations
          ="classpath:applicationContext.xml")
          public class SpringTest extends AbstractJUnit4SpringContextTests {

              @Resource(name
          ="userService")
              
          private UserService userService;
              
              @Test
              
          public void test1(){
                  userService.say();
                  System.out.println();
                  userService.smile();
                  System.out.println();
                  userService.cry();
              }
              
          }
          此單元測(cè)試基于spring的AbstractJUnit4SpringContextTests,你需要添加spring的關(guān)于單元測(cè)試的支持
          在類上標(biāo)注@ContextConfiguration(locations="classpath:applicationContext.xml")意思是去classpath路徑下加載applicationContext.xml
          @Resource(name="userService")意思是把userService注入進(jìn)來(lái)

          最終輸出結(jié)果為:

          ----------before-------------
          say method is called
          ----------after-------------

          ----------before-------------
          smile method is called
          ----------after-------------

          ----------before-------------
          cry method is called
          ----------after-------------




          點(diǎn)我下載工程代碼
          posted @ 2010-10-29 10:36 雪山飛鵠 閱讀(2642) | 評(píng)論 (0)編輯 收藏

          溫馨提示:
                  以下異常僅在Spring3.0.3版本中遇到,其他版本可能也會(huì)遇到,讀者可作參考。不保證會(huì)順利通過(guò)。
                  近期在學(xué)習(xí)Spring3的一些新特性,一般在項(xiàng)目開發(fā)中為了方便期間,都是借助myeclipse工具來(lái)添加ssh支持,很少手動(dòng)添jar包。這里想自虐一下,體驗(yàn)一下jar包沖突或找不到類的那種感覺,在此也將在Spring3.0中AOP開發(fā)過(guò)程中遇到的異常什么的記錄出來(lái),可以方便更多人,快速定位錯(cuò)誤。

          第一個(gè)異常
          java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
          有過(guò)開發(fā)經(jīng)驗(yàn)的一眼就可以看出,這是缺少commons-logging.jar包,因?yàn)閟pring中使用它來(lái)記錄日志,而spring3.0.3這個(gè)版本中并沒有該jar,自行到apache網(wǎng)站下載添加該jar即可

          第二個(gè)異常
          在使用AOP的注解時(shí)需要用到aopalliance.jar 、aspectjrt.jar 、aspectjweaver.jar,而此三個(gè)jar包并未在spring3.0.3的發(fā)布中提供需要開發(fā)者自行添加

          第三個(gè)異常
          org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces
          從異常信息可以看出是cglib的問(wèn)題,而我們?nèi)z查項(xiàng)目,卻發(fā)現(xiàn)項(xiàng)目中并未cglib的jar,那么你可能想到的是缺少cglib這個(gè)jar包,沒錯(cuò),你的思路是正確的,你具有做javaee開發(fā)的思維,添加cglib-2.2.jar即可
          第四個(gè)異常,這也是開發(fā)中每個(gè)人都會(huì)遇到的一個(gè)異常,堪稱ssh開發(fā)中的經(jīng)典,如果你是一位技術(shù)主管,那么你可以同過(guò)此異常去考查一個(gè)新人,一看便知,他有沒有javaee開發(fā)經(jīng)驗(yàn)。呵呵,廢話這么多了,不知道你有沒有猜到是什么了。還是我來(lái)告訴你吧,那就是經(jīng)典的asm.jar包沖突,你的答案正確嗎?不正確,沒關(guān)系,你只要記下如何解決就可以了,這個(gè)異常保證你在工作中遇到或在面試中問(wèn)到,那么它的重要性可想而知了。

          下面分環(huán)境來(lái)介紹該jar包沖突的解決方案。

          在spring3.0以下的環(huán)境中(適應(yīng)于ssh),若出現(xiàn)該jar包沖突,你需要?jiǎng)h除帶版本號(hào)的那個(gè)asm.jar,而保留不帶版本號(hào)的那個(gè)asm.jar即可

          在spring3.0的環(huán)境中,大家仔細(xì)檢查的話發(fā)現(xiàn)spring也帶了一個(gè)名為org.springframework.asm-3.0.3.RELEASE.jar的jar包,而在開發(fā)中僅僅使用這個(gè)jar包還是不夠的,你還需要額外的去添加asm.jar,那么這個(gè)asm.jar到底是那個(gè)版本了?用大腿想想?記得胡叔叔上臺(tái)的時(shí)候提過(guò)與時(shí)俱進(jìn)這個(gè)詞,呵呵,人家是說(shuō)政治的,我這是說(shuō)開發(fā)的,既然spring是3.0的版本,那么asm.jar這個(gè)jar包版本肯定也是3.0以上版本啦,要與時(shí)俱進(jìn)嘛。下載地址http://forge.ow2.org/projects/asm/ 我們會(huì)看到一個(gè)3.3的版本。
          可能見到的異常信息
           java.lang.NoClassDefFoundError: org/objectweb/asm/Type
          org.objectweb.asm.ClassVisitor.visit
          asm3.3.jar,你值得擁有!

          posted @ 2010-10-29 09:46 雪山飛鵠 閱讀(4958) | 評(píng)論 (3)編輯 收藏

               摘要: 使用javamail接收電子郵件代碼 import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStre...  閱讀全文
          posted @ 2010-10-21 11:45 雪山飛鵠 閱讀(2587) | 評(píng)論 (3)編輯 收藏

                  在這一年多時(shí)間里,由于項(xiàng)目多半使用的是jdbc,很少使用到Hibernate、JPA、Ibatis等持久層框架。最多使用上spring的jdbcTemplate 久而久之,之前學(xué)習(xí)的這些持久層框架的映射配置忘的差不多了。借近期有時(shí)間,抽空復(fù)習(xí)了下以上三個(gè)持久層框架?,F(xiàn)將項(xiàng)目中常用的映射關(guān)系的關(guān)聯(lián)配置整理如下:
          JPA:

          JPA主鍵雙向關(guān)聯(lián)一對(duì)一映射

          JPA外鍵雙向關(guān)聯(lián)一對(duì)一映射

          JPA雙向關(guān)聯(lián)多對(duì)一映射

          JPA多對(duì)多雙向關(guān)聯(lián)


          Hibernate:

          Hibernate一對(duì)一主鍵雙向關(guān)聯(lián)映射(xml配置)

          Hibernate一對(duì)一主鍵雙向關(guān)聯(lián)映射(Annotation配置)

          Hibernate一對(duì)一外鍵雙向關(guān)聯(lián)(xml配置篇)

          Hibernate一對(duì)一外鍵雙向關(guān)聯(lián)(Annotation配置篇)

          Hibernate多對(duì)一雙向關(guān)聯(lián)(xml配置)

          Hibernate多對(duì)一雙向關(guān)聯(lián)(Annotation配置)

          Hibernate多對(duì)多雙向關(guān)聯(lián)(xml配置)

          Hibernate多對(duì)多雙向關(guān)聯(lián)(Annotation配置)


          使用Xdoclet和Ant構(gòu)建Hibernate映射和配置文件

          使用Xdoclet和Ant構(gòu)建Hibernate映射和配置文件


          Ibatis
          使用ibatis完成持久化工作


          ibatis陸續(xù)更新中。。。。。期待下篇ibatis多對(duì)一雙向關(guān)聯(lián)映射
          posted @ 2010-10-18 21:41 雪山飛鵠 閱讀(2376) | 評(píng)論 (1)編輯 收藏


          Role.java
          package com.many2many.bean;

          import java.util.Set;

          import javax.persistence.CascadeType;
          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import javax.persistence.GenerationType;
          import javax.persistence.Id;
          import javax.persistence.ManyToMany;
          import javax.persistence.Table;

          @Entity
          @Table(name
          ="roles",catalog="Hibernate_Many2Many")
          public class Role {
              
              
          private int id;
              
          private String name;
              
          private Set<User> users;
              @Id
              @Column(name
          ="id")
              @GeneratedValue(strategy
          =GenerationType.AUTO)
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              @Column(name
          ="name")
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              @ManyToMany(mappedBy
          ="roles",cascade=CascadeType.ALL)
              
          public Set<User> getUsers() {
                  
          return users;
              }
              
          public void setUsers(Set<User> users) {
                  
          this.users = users;
              }
              
          }
          User.java
          package com.many2many.bean;

          import java.util.Set;

          import javax.persistence.CascadeType;
          import javax.persistence.Column;
          import javax.persistence.Entity;
          import javax.persistence.GeneratedValue;
          import javax.persistence.GenerationType;
          import javax.persistence.Id;
          import javax.persistence.JoinColumn;
          import javax.persistence.JoinTable;
          import javax.persistence.ManyToMany;
          import javax.persistence.Table;

          @Entity
          @Table(name
          ="users",catalog="Hibernate_Many2Many")
          public class User {
              
              
          private int id;
              
          private String name;
              
          private Set<Role> roles;
              @Id
              @Column(name
          ="id")
              @GeneratedValue(strategy
          =GenerationType.AUTO)
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              @Column(name
          ="name")
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              @ManyToMany(cascade
          =CascadeType.ALL)
              @JoinTable(
                      name
          ="user_role",
                      joinColumns
          =@JoinColumn(name="user_id"),
                      inverseJoinColumns
          =@JoinColumn(name="role_id")
              )
              
          public Set<Role> getRoles() {
                  
          return roles;
              }
              
          public void setRoles(Set<Role> roles) {
                  
          this.roles = roles;
              }
              
          }
          導(dǎo)出的sql
          create table Hibernate_Many2Many.roles (
                  id 
          integer not null auto_increment,
                  name 
          varchar(255),
                  
          primary key (id)
              )

              
          create table Hibernate_Many2Many.users (
                  id 
          integer not null auto_increment,
                  name 
          varchar(255),
                  
          primary key (id)
              )

              
          create table user_role (
                  
          user_id integer not null,
                  role_id 
          integer not null,
                  
          primary key (user_id, role_id)
              )

              
          alter table user_role 
                  
          add index FK143BF46ADA6B394F (role_id), 
                  
          add constraint FK143BF46ADA6B394F 
                  
          foreign key (role_id) 
                  
          references Hibernate_Many2Many.roles (id)

              
          alter table user_role 
                  
          add index FK143BF46A7F95FD2F (user_id), 
                  
          add constraint FK143BF46A7F95FD2F 
                  
          foreign key (user_id
                  
          references Hibernate_Many2Many.users (id)

          測(cè)試代碼
          @Test
              
          public void insert(){
                  Session session
          =HibernateSessionFactory.getSession();
                  Transaction transaction
          =session.beginTransaction();
                  
          try {
                      transaction.begin();
                      User user
          =new User();
                      user.setName(
          "張三");
                      
                      Role role
          =new Role();
                      role.setName(
          "管理員");
                      Set
          <Role> roles=new HashSet<Role>();
                      roles.add(role);
                      user.setRoles(roles);
                      
                      session.persist(user);
                      
                      transaction.commit();
                  } 
          catch (HibernateException e) {
                      e.printStackTrace();
                      transaction.rollback();
                  }
              }
              
              
              @Test
              
          public void select(){
                  Session session
          =HibernateSessionFactory.getSession();
                  User user
          =(User) session.get(User.class1);
                  System.out.println(user.getName());
                  Set
          <Role> roles=user.getRoles();
                  
          for (Iterator<Role> iterator = roles.iterator(); iterator.hasNext();) {
                      Role role 
          = (Role) iterator.next();
                      System.out.println(role.getName());
                  }
              }
          posted @ 2010-10-18 21:15 雪山飛鵠 閱讀(2135) | 評(píng)論 (1)編輯 收藏


          Role.java
          package com.many2many.bean;

          import java.util.Set;

          public class Role {
              
              
          private int id;
              
          private String name;
              
          private Set<User> users;
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              
          public Set<User> getUsers() {
                  
          return users;
              }
              
          public void setUsers(Set<User> users) {
                  
          this.users = users;
              }
              
          }
          User.java
          package com.many2many.bean;

          import java.util.Set;

          public class User {
              
              
          private int id;
              
          private String name;
              
          private Set<Role> roles;
              
          public int getId() {
                  
          return id;
              }
              
          public void setId(int id) {
                  
          this.id = id;
              }
              
          public String getName() {
                  
          return name;
              }
              
          public void setName(String name) {
                  
          this.name = name;
              }
              
          public Set<Role> getRoles() {
                  
          return roles;
              }
              
          public void setRoles(Set<Role> roles) {
                  
          this.roles = roles;
              }
              
          }
          映射文件
          Role.hbm.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
              
          <hibernate-mapping package="com.many2many.bean">
                  
          <class name="Role" table="roles" catalog="Hibernate_Many2Many">
                      
          <id name="id" column="id">
                          
          <generator class="native"/>
                      
          </id>
                      
          <property name="name" column="name"/>
                      
          <set name="users" table="user_role" cascade="all">
                          
          <key>
                              
          <column name="role_id"/>
                          
          </key>
                          
          <many-to-many column="user_id" class="User"/>
                      
          </set>
                  
          </class>
              
          </hibernate-mapping>

          User.hbm.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE hibernate-mapping PUBLIC 
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
          >
              
          <hibernate-mapping package="com.many2many.bean">
                  
          <class name="User" table="users" catalog="Hibernate_Many2Many">
                      
          <id name="id" column="id">
                          
          <generator class="native"/>
                      
          </id>
                      
          <property name="name" column="name"/>
                      
          <set name="roles" table="user_role" cascade="all">
                          
          <key>
                              
          <column name="user_id"/>
                          
          </key>
                          
          <many-to-many column="role_id" class="Role"/>
                      
          </set>
                  
          </class>
              
          </hibernate-mapping>

          導(dǎo)出的sql
          create table Hibernate_Many2Many.roles (
                  id 
          integer not null auto_increment,
                  name 
          varchar(255),
                  
          primary key (id)
              )

              
          create table Hibernate_Many2Many.users (
                  id 
          integer not null auto_increment,
                  name 
          varchar(255),
                  
          primary key (id)
              )

              
          create table user_role (
                  role_id 
          integer not null,
                  
          user_id integer not null,
                  
          primary key (user_id, role_id)
              )

              
          alter table user_role 
                  
          add index FK143BF46ADA6B394F (role_id), 
                  
          add constraint FK143BF46ADA6B394F 
                  
          foreign key (role_id) 
                  
          references Hibernate_Many2Many.roles (id)

              
          alter table user_role 
                  
          add index FK143BF46A7F95FD2F (user_id), 
                  
          add constraint FK143BF46A7F95FD2F 
                  
          foreign key (user_id
                  
          references Hibernate_Many2Many.users (id)

          測(cè)試代碼
          @Test
              
          public void insert(){
                  Session session
          =HibernateSessionFactory.getSession();
                  Transaction transaction
          =session.beginTransaction();
                  
          try {
                      transaction.begin();
                      User user
          =new User();
                      user.setName(
          "張三");
                      
                      Role role
          =new Role();
                      role.setName(
          "管理員");
                      Set
          <Role> roles=new HashSet<Role>();
                      roles.add(role);
                      user.setRoles(roles);
                      
                      session.persist(user);
                      
                      transaction.commit();
                  } 
          catch (HibernateException e) {
                      e.printStackTrace();
                      transaction.rollback();
                  }
              }
              
              
              @Test
              
          public void select(){
                  Session session
          =HibernateSessionFactory.getSession();
                  User user
          =(User) session.get(User.class1);
                  System.out.println(user.getName());
                  Set
          <Role> roles=user.getRoles();
                  
          for (Iterator<Role> iterator = roles.iterator(); iterator.hasNext();) {
                      Role role 
          = (Role) iterator.next();
                      System.out.println(role.getName());
                  }
              }
          posted @ 2010-10-18 21:06 雪山飛鵠 閱讀(4378) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共22頁(yè): First 上一頁(yè) 6 7 8 9 10 11 12 13 14 下一頁(yè) Last 
          主站蜘蛛池模板: 双桥区| 枣庄市| 大邑县| 行唐县| 平原县| 惠州市| 温宿县| 甘洛县| 乡宁县| 德阳市| 兰考县| 鹤岗市| 息烽县| 房产| 黑山县| 莱西市| 万年县| 宜良县| 泰安市| 甘洛县| 积石山| 盘山县| 鱼台县| 岳池县| 班戈县| 昌黎县| 呼和浩特市| 西昌市| 化州市| 滨州市| 游戏| 正阳县| 莫力| 临潭县| 宜宾县| 如东县| 东光县| 富顺县| 曲沃县| 和平县| 应城市|