隨筆-153  評論-235  文章-19  trackbacks-0
           
                今天,師弟開發(fā)時有遇到一個小問題:struts表單點(diǎn)取消時,出現(xiàn)org.apache.struts.action.InvalidCancelException異常,弄了一陣子,發(fā)現(xiàn)用了validate="true"就會出現(xiàn)此異常。然后找到 freiberg 的博客。

          說到用

          <set-property property="cancellable" value="true"/>

          可以解決,馬上復(fù)制去試下,行喔,^_^。

          ---------------------------------引用--------------------------------------

          Any existing applications that use the Cancel processing will need to modify their struts-config.xml to set the cancellable property for actions which require it.

          In Struts 1.2.9 the <set-property> is used to set the cancellable property for an action....

              <action path="/fooAction"
          input="/foo.jsp"
          validate="true">
          <set-property property="cancellable" value="true"/>
          <forward name="success" path="/bar.jsp"/>
          </action>
          

          From Struts 1.3.x a new cancellable attribute can be used....

              <action path="/fooAction"
          input="/foo.jsp"
          validate="true"
          cancellable="true">
          <forward name="success" path="/bar.jsp"/>
          </action>
          

          In both Struts 1.2.9 and Struts 1.3.x an exception handler can be configured to handle the InvalidCancelException

              <action path="/fooAction"
          input="/foo.jsp"
          validate="true"
          cancellable="true">
          <forward name="success" path="/bar.jsp"/>
          <exception key="errors.cancel"
          type="org.apache.struts.action.InvalidCancelException"
          path="/foo.jsp"/>
          </action>
          

          ---------------------------------------end-----------------------------------------------------

          剛好我用的是struts是1.2.9的

          原文:http://www.aygfsteel.com/freiberg/archive/2007/10/20/154384.html

          posted @ 2007-10-31 16:25 流浪汗 閱讀(1426) | 評論 (1)編輯 收藏
                今天,師弟更新數(shù)據(jù)的時候出現(xiàn)問題。出現(xiàn)“更新分區(qū)關(guān)鍵字列將導(dǎo)致分區(qū)的更改” ,看了下數(shù)據(jù)庫,更新的表有分區(qū),而且更新的字段是分區(qū)的關(guān)鍵字(從報錯可以看出來了)。
                網(wǎng)上找了下,說用這樣可以:

          alter table xxx enable row_movement;

          但我沒有試也沒有這樣做,可能是不放心,解決辦法是不更新分區(qū)的關(guān)鍵字(因?yàn)橄到y(tǒng)不用更新它的,之前更新是因?yàn)閔ibernate處理它了)。如果的確要更新可以先刪除了,再添加一個。引用http://www.itpub.net/283642,1.html

          Question: Why am I getting an ora-14402 error when I update a partition key
          Answer: You cannot update the value of the partition key, the only way you can go about this is by deleting the old row and adding a new row to the table


          posted @ 2007-10-29 21:09 流浪汗 閱讀(4342) | 評論 (0)編輯 收藏

                與寫對應(yīng)的是讀.

           

          package net.blogjava.chenlb;

          import java.io.IOException;
          import java.io.InputStream;
          import java.util.ArrayList;
          import java.util.List;

          import jxl.Cell;
          import jxl.Sheet;
          import jxl.Workbook;
          import jxl.read.biff.BiffException;


          /**
           * jxl 的Excel閱讀器.
           * 
          @author chenlb 2007-10-20 下午01:36:01
           
          */
          public class JxlExcelReader {
              
              
          /**
               * 
          @return 返回String[] 的列表
               
          */
              
          public List readExcel(InputStream in) {
                  List lt 
          = new ArrayList();
                  Workbook wb 
          = null;
                  
                  
          try {
                      wb 
          = Workbook.getWorkbook(in);
                      Sheet[] sheets 
          = wb.getSheets();    //獲取工作
                      for(int i=0; i<sheets.length; i++) {
                          Sheet sheet 
          = sheets[i];
                          
          for(int j=0; j<sheet.getRows(); j++) {
                              Cell[] cells 
          = sheet.getRow(j);    //讀取一行
                              if(cells != null && cells.length > 0) {    //這一行有內(nèi)容才添加
                                  String[] dataCells = new String[cells.length];
                                  
          for(int k=0; k<cells.length; k++) {
                                      dataCells[k] 
          = ""+cells[k].getContents(); //讀內(nèi)容
                                  }//column
                                  lt.add(dataCells);
                              }
                          }
          //one sheet
                      }//xls file
                  } catch (BiffException e) {
                      e.printStackTrace();
                  } 
          catch (IOException e) {    
                      e.printStackTrace();
                  } 
          finally {
                      
          if(wb != null) {
                          wb.close();
                      }
                  }
                  
                  
          return lt;
              }

          }
          posted @ 2007-10-29 11:04 流浪汗 閱讀(1009) | 評論 (0)編輯 收藏
                項(xiàng)目中要寫excel,把這個例子寫出來,以后可以看。

          1.寫excel類
          package net.blogjava.chenlb;

          import java.io.IOException;
          import java.io.OutputStream;
          import java.util.List;

          import jxl.Workbook;
          import jxl.write.Label;
          import jxl.write.WritableSheet;
          import jxl.write.WritableWorkbook;
          import jxl.write.WriteException;
          import jxl.write.biff.RowsExceededException;

          /**
           * Jxl 的 Excel寫數(shù)據(jù)器.
           * 
          @author chenlb 2007-10-29 上午10:39:31
           
          */
          public class JxlExcelWriter {
              
              
          /**
               * 
          @param datas 封裝著Object[]的列表, 一般是String內(nèi)容.
               * 
          @param title 每個sheet里的標(biāo)題.
               
          */
              
          public void writeExcel(OutputStream out, List datas, String[] title) {
                  
          if(datas == null) {
                      
          throw new IllegalArgumentException("寫excel流需要List參數(shù)!");
                  }
                  
          try {
                      WritableWorkbook workbook 
          = Workbook.createWorkbook(out);
                      WritableSheet ws 
          = workbook.createSheet("sheet 1"0);
                      
          int rowNum = 0;    //要寫的行
                      if(title != null) {
                          putRow(ws, 
          0, title);//壓入標(biāo)題
                          rowNum = 1;
                      }
                      
          for(int i=0; i<datas.size(); i++, rowNum++) {//寫sheet
                          Object[] cells = (Object[]) datas.get(i);
                          putRow(ws, rowNum, cells);    
          //壓一行到sheet
                      }
                      
                      workbook.write();
                      workbook.close();    
          //一定要關(guān)閉, 否則沒有保存Excel
                  } catch (RowsExceededException e) {
                      System.out.println(
          "jxl write RowsExceededException: "+e.getMessage());
                  } 
          catch (WriteException e) {
                      System.out.println(
          "jxl write WriteException: "+e.getMessage());
                  } 
          catch (IOException e) {
                      System.out.println(
          "jxl write file i/o exception!, cause by: "+e.getMessage());
                  }
              }

              
          private void putRow(WritableSheet ws, int rowNum, Object[] cells) throws RowsExceededException, WriteException {
                  
          for(int j=0; j<cells.length; j++) {//寫一行
                      Label cell = new Label(j, rowNum, ""+cells[j]);
                      ws.addCell(cell);
                  }
              }
          }

          2.使用
              public void testWriteExcel() {
                  List datas 
          = new ArrayList();
                  String[] data 
          = {"1""chenlb"};
                  datas.add(data);
                  
          try {
                      OutputStream out 
          = new FileOutputStream(new File("doc/chenlb.blogjava.net.xls"));
                      JxlExcelWriter jxlExcelWriter 
          = new JxlExcelWriter();
                      jxlExcelWriter.writeExcel(out, datas, 
          new String[] {"Id""name"});
                      out.close();
                  } 
          catch (FileNotFoundException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  } 
          catch (IOException e) {
                      
          // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
                  
              }

          posted @ 2007-10-29 10:52 流浪汗 閱讀(5918) | 評論 (1)編輯 收藏
                當(dāng)為遺留系統(tǒng)加入spring時,經(jīng)典問題就是遺留系統(tǒng)需要引用spring管理的bean。幸好spring有機(jī)制可以處理這些。

          建一個類實(shí)現(xiàn)ApplicationContextAware接口,有一個引用ApplicationContext的靜態(tài)成員,然后,遺留系統(tǒng)需要引用spring管理的bean的地方,使用這個類。

          1.比如:我這里建一個SpringContext類

          package net.blogjava.chenlb;

          import org.springframework.beans.BeansException;
          import org.springframework.context.ApplicationContext;
          import org.springframework.context.ApplicationContextAware;

          /**
           * 此類可以取得Spring的上下文.
           * Spring 使new方法創(chuàng)建的對象可以引用spring管理的bean.
           * 2007-10-18 上午11:12:33
           * 
          @author chenlb
           
          */
          public class SpringContext implements ApplicationContextAware {

              
          protected static ApplicationContext context;
              
              
          public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
                  context 
          = applicationContext;
              }

              
          public static ApplicationContext getContext() {
                  
          return context;
              }

          }

          2.然后在spring配置文件里加
          <bean id="springContext" class="net.blogjava.chenlb.SpringContext"></bean>

          3.其它類中引用
          MyBean myBean = (MyBean) SpringContext.getContext().getBean("myBean");

          4.如果老是寫SpringContext.getContext().getBean("...");麻煩,可以建一個工廠類來返回你要的bean
          package net.blogjava.chenlb;



          public class MyServerFactory {


              
          public static MyBean1 getMyBean1() {
                  
          return (MyBean1) SpringContext.getContext().getBean("myBean1");
              }
              

          }


          ^_^
          posted @ 2007-10-27 16:31 流浪汗 閱讀(15437) | 評論 (1)編輯 收藏
               jstl 1.0 formatDate yyyy-mm 不能正常工作,格式出來的月是00,要用yyyy-MM,才能,郁悶。
          posted @ 2007-10-25 22:38 流浪汗 閱讀(375) | 評論 (1)編輯 收藏
                開發(fā)項(xiàng)目,今天又難到問題。junit測試寫數(shù)據(jù)到oracle時,出現(xiàn):ORA-01461: can bind a LONG value only for insert into a LONG column錯誤,郁悶,試了幾次發(fā)現(xiàn),中文才會有這個問題,而且jsp頁面里輸入的中文又不會報這個錯(前端是struts)。像mysql的話,很有可能是數(shù)據(jù)庫字符編碼問題,就懷疑是否為字符編碼問題(這種思維不知道會不會很傻),因?yàn)轫?xiàng)目所有編碼都是utf-8, 看了下oracle是zhs16GBK。然后就建一個gbk的項(xiàng)目來測試,結(jié)果還是出現(xiàn)此問題。后來就換用舊系統(tǒng)的classes12.jar驅(qū)動測試下,^_^, 不會了,太好了。看了下classes12.jar的版本是9.0.2.0.0的而且又是classes12.jar不爽,后來看到一個帖子,說:用9的和10.2的沒有此問題,我回去看下之前出問題的版本是10.1.0.2.0,郁悶,用的數(shù)據(jù)庫是10.2.0.1.0。馬上換成10.2.0.1.0的版本。當(dāng)初不注意,今天花了我?guī)讉€小時。我一直以為jdbc是數(shù)據(jù)庫對應(yīng)的。

          對應(yīng)的jdbc在oracle安裝目錄可以找到oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar

          問題總算解決,^_^
          posted @ 2007-10-20 21:08 流浪汗 閱讀(25285) | 評論 (14)編輯 收藏

                用java好久了,還沒有寫個壓縮文件的示例,昨晚弄了下,把寫下來,以后可以看。

          關(guān)系到
          java.util.zip.ZipEntry
          java.util.zip.ZipOutputStream

          如果要解決中文文件名問題,用到ant.jar

          這兩個類。

          ZipOutputStream.putNextEntry(ZipEntry);就可以了,然后ZipOutputStream.wirte();就得了。

          package net.blogjava.chenlb.zip;

          import java.io.BufferedOutputStream;
          import java.io.File;
          import java.io.FileInputStream;
          import java.io.FileNotFoundException;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.OutputStream;
          //import java.util.zip.ZipEntry;
          //import java.util.zip.ZipOutputStream;
          //用ant.jar的zip.*可以解決中文文件名問題
          import org.apache.tools.zip.ZipEntry;
          import org.apache.tools.zip.ZipOutputStream;

          /**
           * 壓縮文件.
           * 2007-10-17 下午11:19:50
           * 
          @author chenlb
           
          */
          public class RecursiveZip {

              
              
          public static void main(String[] args) {

                  RecursiveZip recursiveZip 
          = new RecursiveZip();
                  System.out.println(
          "====開始====");
                  
          try {
                      OutputStream os 
          = new FileOutputStream("e:/doc-recursive.zip");
                      BufferedOutputStream bs 
          = new BufferedOutputStream(os);
                      ZipOutputStream zo 
          = new ZipOutputStream(bs);
                      
                      
          //recursiveZip.zip("e:/recursive-zip/中文文件名.txt", new File("e:/recursive-zip"), zo, true, true);
                      recursiveZip.zip("e:/recursive-zip"new File("e:/recursive-zip"), zo, truetrue);
                      
                      zo.closeEntry();
                      zo.close();
                  } 
          catch (FileNotFoundException e) {
                      e.printStackTrace();
                  } 
          catch (IOException e) {
                      e.printStackTrace();
                  }
                  System.out.println(
          "====完成====");
              }

              
          /**
               * 
          @param path 要壓縮的路徑, 可以是目錄, 也可以是文件.
               * 
          @param basePath 如果path是目錄,它一般為new File(path), 作用是:使輸出的zip文件以此目錄為根目錄, 如果為null它只壓縮文件, 不解壓目錄.
               * 
          @param zo 壓縮輸出流
               * 
          @param isRecursive 是否遞歸
               * 
          @param isOutBlankDir 是否輸出空目錄, 要使輸出空目錄為true,同時baseFile不為null.
               * 
          @throws IOException
               
          */
              
          public void zip(String path, File basePath, ZipOutputStream zo, boolean isRecursive, boolean isOutBlankDir) throws IOException {
                  
                  File inFile 
          = new File(path);

                  File[] files 
          = new File[0];
                  
          if(inFile.isDirectory()) {    //是目錄
                      files = inFile.listFiles();
                  } 
          else if(inFile.isFile()) {    //是文件
                      files = new File[1];
                      files[
          0= inFile;
                  }
                  
          byte[] buf = new byte[1024];
                  
          int len;
                  
          //System.out.println("baseFile: "+baseFile.getPath());
                  for(int i=0; i<files.length; i++) {
                      String pathName 
          = "";
                      
          if(basePath != null) {
                          
          if(basePath.isDirectory()) {
                              pathName 
          = files[i].getPath().substring(basePath.getPath().length()+1);
                          } 
          else {//文件
                              pathName = files[i].getPath().substring(basePath.getParent().length()+1);
                          }
                      } 
          else {
                          pathName 
          = files[i].getName();
                      }
                      System.out.println(pathName);
                      
          if(files[i].isDirectory()) {
                          
          if(isOutBlankDir && basePath != null) {    
                              zo.putNextEntry(
          new ZipEntry(pathName+"/"));    //可以使空目錄也放進(jìn)去
                          }
                          
          if(isRecursive) {    //遞歸
                              zip(files[i].getPath(), basePath, zo, isRecursive, isOutBlankDir);
                          }
                      } 
          else {
                          FileInputStream fin 
          = new FileInputStream(files[i]);
                          zo.putNextEntry(
          new ZipEntry(pathName));
                          
          while((len=fin.read(buf))>0) {
                              zo.write(buf,
          0,len);
                          }
                          fin.close();
                      }
                  }
              }
          }


          posted @ 2007-10-18 13:53 流浪汗 閱讀(3031) | 評論 (3)編輯 收藏
                昨天出了一個奇怪的問題,hibernate通過實(shí)體Id(char(10)型)取得數(shù)據(jù),session.find("from TableName where id=?","value");取不到數(shù)據(jù),但數(shù)據(jù)庫里是有這個條數(shù)據(jù)。真奇怪,后來用pl/sql看數(shù)據(jù)庫,鼠標(biāo)點(diǎn)到Id那時,可以看到內(nèi)容后面還有一些空格,帶著期望與質(zhì)疑把字段里的值自制過來, session.find("from TableName where id=?","value    ");后發(fā)現(xiàn)可以。我特別試了下connection.createStatement("select * from table_name where id='value'");則正常取數(shù)據(jù),session.find("from TableName where id=?","value");而卻找不到數(shù)據(jù),然后又試了下
          ptmt = connection.prepareStatement(select * from table_name where id=?");
          ptmt.setString(1,"year");

          這樣也不行,以是結(jié)論是:jdbc驅(qū)動PrepareStatement對char字段類型的查找問題,因?yàn)閔ibernate是用PrepareStatement的,自然,hibernate對char對應(yīng)的屬性條件查找出現(xiàn)找不到的情況,

          解決辦法是:
          1.屬性用TRIM函數(shù)處理:session.find("from TableName where TRIM(id)=?","value");
          2.char改為varchar2類型

          今天試了下mysql,它不會這樣的情況,所以結(jié)論是:Oracle JDBC PreparedStatement的bug(有可能它故意這樣)


          posted @ 2007-10-17 22:22 流浪汗 閱讀(5576) | 評論 (1)編輯 收藏
                jsp 直接輸出二進(jìn)制文件怎么辦呢?

          download.jsp
          <%@ page language="java" pageEncoding="utf-8"%>
          <%@ page import="java.io.*" %>
          <%
          try {
              FileInputStream fin 
          = new FileInputStream(application.getRealPath("/")+"/readme.zip");
              response.addHeader(
          "Content-Disposition","attachment;filename=read.zip"); 
              
          byte[] buf = new byte[1024];
              
          int readSize = fin.read(buf);
              OutputStream os 
          = response.getOutputStream();
              
              
          while(readSize != -1) {
                  os.write(buf, 
          0, readSize);
                  readSize 
          = fin.read(buf);
              }
              os.flush();
              os.close();
              os 
          = null ;
              response.flushBuffer();
              out.clear();
              out  
          =  pageContext.pushBody();
                  
          catch (IllegalStateException e) {

          }
          %>

          webapps/test/readme.zip文件可以被下載,可能第一次會輸出文字。
          posted @ 2007-10-16 23:57 流浪汗 閱讀(580) | 評論 (0)編輯 收藏
          僅列出標(biāo)題
          共16頁: First 上一頁 4 5 6 7 8 9 10 11 12 下一頁 Last 
          主站蜘蛛池模板: 吴堡县| 苏州市| 陈巴尔虎旗| 乾安县| 双流县| 天水市| 六盘水市| 苍梧县| 虹口区| 泾阳县| 定襄县| 信宜市| 磴口县| 政和县| 资阳市| 威信县| 温泉县| 德兴市| 沙坪坝区| 富平县| 尼勒克县| 三河市| 拜泉县| 金堂县| 无锡市| 二手房| 德保县| 贵港市| 怀安县| 临洮县| 望谟县| 金坛市| 固始县| 永济市| 阿瓦提县| 德阳市| 敦煌市| 长治县| 志丹县| 荃湾区| 汶上县|