Jcat
宠辱不惊,闲看庭前花开花落~~
posts - 173,comments - 67,trackbacks - 0
状:刚配置好struts,可是DispatchAction怎么都不工作(Action可以工作),也不报错
原因:只引入了struts自身的jar,看一看release中lib下,还有不少非struts的jar,可以猜想这些都是DispatchAction所需要的,而Action不需要(以前以为这些没用)。不报错让我很郁闷。



状:刚配置好struts,action可以工作了,就是不能正确的forward到jsp页面,execute中加断点,也不进入。
原因:execute有两个!!!HttpServletRequest vs ServletRequest,前者才是struts所使用的execute。



状:在web.xml里面设置好了

<error-page>
        
<error-code>404</error-code>
        
<location>/404.jsp</location>
</error-page>

但当出现404错误时,并没有显示404.jsp这一页,而是显示browser提供的error report page

原因:在客户端浏览器如IE的internet选项高级属性中默认使用“友好的http错误信息”,这样会造成你的服务器是输出你所定义的错误页面,但到客户端被IE这混蛋给覆盖掉了。解决方案是你定义的错误页面的大小必须大于512bytes,就不会被客户端设置所影响了。



状:用hibernate访问数据库,可以insert,可以select,可以drop,就是不能update,而且没有任何错误消息

原因:
<class name="com.verican.base.model.CatalogPO" table="sys_catalog" mutable="false">设置成true即可。
(当mutable=false,却又执行update操作时,hibernate至少应该提供警告消息告知一下才对,可惜没有,所以很难发现)



状:
      Javascript弹出窗口时,如果用的是相对路径,形如javascript:void(window.open('../../test.html')),不同的浏览器的处理不同(因为js是浏览器处理的东西)。
      比如,不是部署在根目录下时(根目录下又建了一个目录):在Firefox下,是以服务器为视角,则../../即可;而在IE下,则是以浏览器为视角,则需要多加一级,如../../../
            
解决:用绝对路径 javascript:void(window.open('http://www.verican.com/test.html'));或者,用 <a target="_blank" href="../../test.html"> (因为这是服务器处理的东西,所以不管部署在哪里,相对路径都是唯一确定的)



状:
刷新的时候 1)抛出ServletException
                     2)The page cannot be refreshed without resending the information, Click Retry to send the information again.

原因:Struts中redirect设置问题(具体原理以后再研究)

解决:一般的,forward到一个具体的page,redirect=false;forward到另一个action,redirect=true
           
<forward name="add_item" path="newsletter.add_item.page" redirect="false"/>
<forward name="success" path="/newsletter.do" redirect="true"/>


状:

save a form --> forward to list page --> refresh --> retry --> save the form again (error)


原因:
<forward name="list" path="ticket.list.page" redirect="false"/>

解决:一般的,从save一个表单后,应该forward到另一个action,且redirect=true(而不是另一个page,即便当前action里有这个page)。这样可以保证不会通过刷新重复save数据。
<forward name="list" path="ticket.do" redirect="true"/>



状:
      用Spring + Velocity发email,开始都好好的,也能现实图片,但当加入某一幅图片以后,无法正常显示(得到一个页面为空白的Email,虽然也有大小)。把图片从bmp换到jpg,再换到gif,未果。减小图片的尺寸、大小,未果。几乎都要绝望了~~~

原因:NOTE: Invoke addInline after setText; else, mail readers might not be able to resolve inline references correctly.(这是Spring API里的原话,NND)

感受:
      1.以前没写过发Email的程序,工作中用到了,照猫画虎拿过来就用,也没有仔细阅读文档,导致这次惨痛的教训。
      2.Spring中这部分设计的也有问题,它在两个表面上没什么关系的方法之间,建立了顺序上的依赖关系。这使得出现这种情况时,没有任何线索。



状:
遍历List时,一调用remove就出错,(错误的)代码如下
for (Object o : list)
    
{
            list.remove(o);
        }

原因:ConcurrentModificationException,有remove操作时,不能用foreach循环

解决:用传统循环(看了传统还是很有用的)
for (int i = 0; i < list.size(); i++)
    
{
            list.remove(i
--);
        }
注意remove过需要 i--  (--i is wrong)



状:
boolean b = new Integer(3== new Integer(3); //false

原因:其实是很简单的问题,但是IDEA只会对String的 = = 做智能提示,注意即可。



状:
org.hibernate.MappingException: Could not read mappings from resource: jcat/learn/mapping.xml
 
开始以为路径没写对,试验了N中路径的写发后,还是不行。后来才发现是因为mapping.xml是空的。
 
解决:给mapping.xml加上一个空壳就可以了(好歹空壳不等于空)
 
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping default-lazy="false">

</hibernate-mapping>
 
NOTE:几种路径的写法
1. classpath:packagename/filename
例子:在applicationContext.xml中注册hibernate.cfg.xml
<bean id="GlobalHibernateSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        
<property name="dataSource">
            
<ref local="GlobalDataSource"/>
        
</property>
        
<property name="configLocation">
            
<value>classpath:hibernate.cfg.xml</value>
        
</property>
</bean>

2. packagename/filename
例子:在hibernate.cfg.xml中注册mapping.xml
<mapping resource="jcat/learn/hibernate_in_spring/orm.xml"/>


状:提交表单程序,加入了上传文件的功能后,出现异常
java.lang.IllegalArgumentException: Cannot invoke com.verican.newsadmin.form.TicketForm.setUploadFile - argument type mismatch

解决:将表单声明为mulptipart类型
<html:form action="/ticket" enctype="multipart/form-data">
         
<html:file property="uploadFile"/>
</html:form>



状:IE cannot open the Internet site file: ....
<html>
<head>
    
<title></title>
</head>
<body>
    
<span id="TypeDes2"/>
    
<script type="text/javascript">
       TypeDes2.innerHTML 
= "Test Span";
    
</script>
</body>
</html>

解决:对于单标签,浏览器找不到innerHTML属性。改为双标签即可。
<span id="TypeDes2"></span>
posted on 2006-07-25 13:11 Jcat 阅读(761) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: