<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

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

    說到用

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

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

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

    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.tkk7.com/freiberg/archive/2007/10/20/154384.html

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

    alter table xxx enable row_movement;

    但我沒有試也沒有這樣做,可能是不放心,解決辦法是不更新分區的關鍵字(因為系統不用更新它的,之前更新是因為hibernate處理它了)。如果的確要更新可以先刪除了,再添加一個。引用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 流浪汗 閱讀(4338) | 評論 (0)編輯 收藏

          與寫對應的是讀.

     

    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) {    //這一行有內容才添加
                            String[] dataCells = new String[cells.length];
                            
    for(int k=0; k<cells.length; k++) {
                                dataCells[k] 
    = ""+cells[k].getContents(); //讀內容
                            }//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 流浪汗 閱讀(1004) | 評論 (0)編輯 收藏
          項目中要寫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寫數據器.
     * 
    @author chenlb 2007-10-29 上午10:39:31
     
    */
    public class JxlExcelWriter {
        
        
    /**
         * 
    @param datas 封裝著Object[]的列表, 一般是String內容.
         * 
    @param title 每個sheet里的標題.
         
    */
        
    public void writeExcel(OutputStream out, List datas, String[] title) {
            
    if(datas == null) {
                
    throw new IllegalArgumentException("寫excel流需要List參數!");
            }
            
    try {
                WritableWorkbook workbook 
    = Workbook.createWorkbook(out);
                WritableSheet ws 
    = workbook.createSheet("sheet 1"0);
                
    int rowNum = 0;    //要寫的行
                if(title != null) {
                    putRow(ws, 
    0, title);//壓入標題
                    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();    
    //一定要關閉, 否則沒有保存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 流浪汗 閱讀(5912) | 評論 (1)編輯 收藏
          當為遺留系統加入spring時,經典問題就是遺留系統需要引用spring管理的bean。幸好spring有機制可以處理這些。

    建一個類實現ApplicationContextAware接口,有一個引用ApplicationContext的靜態成員,然后,遺留系統需要引用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方法創建的對象可以引用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 流浪汗 閱讀(15426) | 評論 (1)編輯 收藏
         jstl 1.0 formatDate yyyy-mm 不能正常工作,格式出來的月是00,要用yyyy-MM,才能,郁悶。
    posted @ 2007-10-25 22:38 流浪汗 閱讀(373) | 評論 (1)編輯 收藏
          開發項目,今天又難到問題。junit測試寫數據到oracle時,出現:ORA-01461: can bind a LONG value only for insert into a LONG column錯誤,郁悶,試了幾次發現,中文才會有這個問題,而且jsp頁面里輸入的中文又不會報這個錯(前端是struts)。像mysql的話,很有可能是數據庫字符編碼問題,就懷疑是否為字符編碼問題(這種思維不知道會不會很傻),因為項目所有編碼都是utf-8, 看了下oracle是zhs16GBK。然后就建一個gbk的項目來測試,結果還是出現此問題。后來就換用舊系統的classes12.jar驅動測試下,^_^, 不會了,太好了。看了下classes12.jar的版本是9.0.2.0.0的而且又是classes12.jar不爽,后來看到一個帖子,說:用9的和10.2的沒有此問題,我回去看下之前出問題的版本是10.1.0.2.0,郁悶,用的數據庫是10.2.0.1.0。馬上換成10.2.0.1.0的版本。當初不注意,今天花了我幾個小時。我一直以為jdbc是數據庫對應的。

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

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

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

    關系到
    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+"/"));    //可以使空目錄也放進去
                    }
                    
    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 流浪汗 閱讀(3029) | 評論 (3)編輯 收藏
          昨天出了一個奇怪的問題,hibernate通過實體Id(char(10)型)取得數據,session.find("from TableName where id=?","value");取不到數據,但數據庫里是有這個條數據。真奇怪,后來用pl/sql看數據庫,鼠標點到Id那時,可以看到內容后面還有一些空格,帶著期望與質疑把字段里的值自制過來, session.find("from TableName where id=?","value    ");后發現可以。我特別試了下connection.createStatement("select * from table_name where id='value'");則正常取數據,session.find("from TableName where id=?","value");而卻找不到數據,然后又試了下
    ptmt = connection.prepareStatement(select * from table_name where id=?");
    ptmt.setString(1,"year");

    這樣也不行,以是結論是:jdbc驅動PrepareStatement對char字段類型的查找問題,因為hibernate是用PrepareStatement的,自然,hibernate對char對應的屬性條件查找出現找不到的情況,

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

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


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

    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 流浪汗 閱讀(577) | 評論 (0)編輯 收藏
    僅列出標題
    共16頁: First 上一頁 4 5 6 7 8 9 10 11 12 下一頁 Last 
    主站蜘蛛池模板: 亚洲Aⅴ无码专区在线观看q| 黄色网页在线免费观看| 无码av免费毛片一区二区| 国产精品亚洲аv无码播放| 免费国产高清毛不卡片基地| 免费看无码自慰一区二区| 亚洲国产精品免费在线观看| 麻豆成人久久精品二区三区免费| 亚洲婷婷五月综合狠狠爱| 国产成人高清精品免费观看| 免费在线一级毛片| 18禁亚洲深夜福利人口| 啦啦啦手机完整免费高清观看| 亚洲精品中文字幕无乱码麻豆| 亚洲免费在线视频观看| 亚洲黄色网站视频| 99精品在线免费观看| 亚洲国产精品自在在线观看 | 亚洲成av人片在线观看天堂无码| 亚洲爆乳大丰满无码专区| 最近中文字幕无免费视频| 亚洲一级毛片免费看| 九九精品免费视频| 亚洲人成人网毛片在线播放| 中文字幕无码不卡免费视频| 亚洲xxxxxx| 妞干网在线免费视频| 亚洲女子高潮不断爆白浆| 免费黄网在线观看| 亚洲AV成人无码网站| 免费A级毛片无码A| 成人福利在线观看免费视频| 久久精品亚洲乱码伦伦中文| 成人网站免费大全日韩国产| 亚洲午夜福利AV一区二区无码| a级特黄毛片免费观看| 久久久久久久久亚洲| **真实毛片免费观看| 亚洲无成人网77777| 毛片a级三毛片免费播放| 亚洲AV无码一区二区三区久久精品|