随笔-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.blogjava.net/freiberg/archive/2007/10/20/154384.html

posted @ 2007-10-31 16:25 流浪汗 阅读(1422) | 评论 (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 流浪汗 阅读(4334) | 评论 (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 流浪汗 阅读(5911) | 评论 (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 流浪汗 阅读(15420) | 评论 (1)编辑 收藏
     jstl 1.0 formatDate yyyy-mm 不能正常工作,格式出来的月是00,要用yyyy-MM,才能,郁闷。
posted @ 2007-10-25 22:38 流浪汗 阅读(372) | 评论 (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 流浪汗 阅读(25268) | 评论 (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 流浪汗 阅读(3027) | 评论 (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 流浪汗 阅读(5553) | 评论 (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 流浪汗 阅读(576) | 评论 (0)编辑 收藏
仅列出标题
共16页: First 上一页 4 5 6 7 8 9 10 11 12 下一页 Last