JAVA错误处理大集合
13.编写clone时从Java编程思想(2nd)上学到的(732):
.引数传递过程中会自动产生别名(alias)。
.没有局域对象(local objects),只有局域性的(local)references。
.reference受范围(scope)的限制,对象则否。
.对象的寿命从来不是Java的讨论议题(因为有垃圾回收机制)
14.try catch finally的域居然是分离的。
15.jsp乱码的其中一个原因:charset="gb2312" 等号"="的两边不允许有空格。
16.我的基于Displaytag的简单报表解决方案。
http://displaytag.sourceforge.net/
下载displaytag.jar和displaytag.tld
displaytag.jar放在lib目录,而displaytag.tld放在WEB-INF目录,在web.xml中为displaytag.tld声明一下。
<taglib>
<taglib-uri>http://displaytag.org</taglib-uri>
<taglib-location>/WEB-INF/displaytag.tld</taglib-location>
</taglib>
在jsp里使用前,加上
<%@ taglib uri="http://displaytag.org" prefix="display" %>
注意该软件有个bug,他要用的一个包common-lang.jar版本必须在2.0以上。
如果碰到下面异常,则应坚持一下是否该包的版本问题。
java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.capitalize(Ljava/lang/String;)Ljava/lang/String;
然后就可放心使用了
<display:column property = "xxx"/>其中xxx为对象中的带有getter的变量>。
定义表格的样子,用css定义。如
TABLE.its THEAD TR {
BACKGROUND-COLOR: #69c
}
TABLE.its TR.even {
BACKGROUND-COLOR: #def
}
在使用分页时,可能会出现这种情况,点击其他页时,弹出下载窗口,让你下载当前jsp页面,这是因为你在当前页面读取了数据的缘故。解决办法为在action里读取数据而不是在jsp里。可以参考
http://www.displaytag.org/example-paging.jsp?d-26189-p=2
17.使用displaytag时,在一列中放入多个元素
必须在display:table中定义一个id
<display:table name = "allBooks" class = "its" pagesize = "5" id = "item">
<display:column title = "操作">
<a href = "/Bookshop/admin/bookManagement.do?action=view&id=<%=((Book)item).getId()%>" target = "_blank" >查看</a>
<a href = "/Bookshop/admin/bookManagement.do?action=edit&id=<%=((Book)item).getId()%>">编辑</a>
<a href = "/Bookshop/admin/bookManagement.do?action=delete&id=<%=((Book)item).getId()%>">删除</a>
</display:column>
要在displaytag中使用链接,必须具备paramId,否则不显示为链接
<display:column property = "product.name" href = "viewDetailV2.0.jsp" title = "书名" paramId="item" paramProperty="product.id"/>
可以这样使用display
<display:column property = "product.id" title = "ID"/>
其中product为对象
18.<bean:write name = "xxxx" property = "xxx"/> 可以直接取到session.getAttribute()取到的东西。
19.实验struts-upload例子时要注意的地方:
1.If you would rather write this file to another file, please check here:
这一行要打钩
2.If you checked the box to write to a file, please specify the file path here:
在这里要重命名如:c:\b.jpg
上传成功的话,会出现提示 The file has been written to "c:\b.jpg"
20.Hibernate的like可以这么用:
Query query = session.createQuery("from src.persistent.Book as book where upper(book.name) like :name ");
query.setString("name", "%");
result = query.list();
21.Hibernate出现 duplicate import : className
异常也可能是因为忘了为持久类在configuration中addClass了
22.<logic:iterate id = "author" name = "authors">
name所引用的是session里的attribute。
23.如果发现要出现询问下载的情况,有可能是因为要跳转的页面出现了问题。试试在要跳转到的页删掉
<%@ page contentType="text/html; charset=gb2312"%>
24.如果JSP页面跳转时出现下边的错误信息:
The request sent by the client was syntactically incorrect (Invalid path /web/shoppingCart was requested).
原因是struts-config的action = "x" 写成了 action = "x.do"
25.在struts中,strut-config.xml中,forward时使用redirect = "true"可以将.do重定向为.jsp
26.以后在判断相等性之前先用logger把两个值显示出来。
27.从session里getAttribute后,修改并不需要重新setAttribute一次。
28.在hibernate中使用subclass是一棵继承树共用一个表,仅生成个mapping。
每个类中必须有discrimator-value。在最上层的类中必须声明:
@hibernate.discriminator column = "class"。
不可以将子类添加到configuration里去。(即不可addClass(子类))
使用Xdoclet的建立subclass的例子(该类是父类)
/**
* @hibernate.class discriminator-value = "customer"
* @hibernate.discriminator column = "class"
*/
而使用joined-subclass则是一类一表,也不许将子类添加进configuration里去。
/**
* @hibernate.joined-subclass
* @hibernate.joined-subclass-key
* column="customer_id"
*/
如果发现生成的mapping文件中joined-subclass的key column为空,那么可能是@hibernate.joined-subclass-key这句没有写对。
用joined-subclass生成的表,仔细看。Member extends Customer
create table Customer (
id VARCHAR2(255) not null,
name VARCHAR2(255),
description VARCHAR2(255),
primary key (id)
)
create table Member (
customer_id VARCHAR2(255) not null,
password VARCHAR2(255),
primary key (customer_id)
)
29.在junit中尽量使用assertEquals代替assertTrue;
30.Hibernate
如果Child extends Parent
那么from Parent as parent 也将会将Child选出来,而from Child as child 则不会选出Parent
31.Hibernate
使用hibernate的one-to-one时,应该两方向都set,否则会报save NullPointException
parent.setChild(child);
child.setParent(parent);
32.Hibernate
遇到下边的异常,估计是与因为外键出现了问题:
java.lang.NullPointerException
at net.sf.hibernate.persister.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:675)
at net
推荐文章 |
