Struts2.0异常总结

 1、异常信息:The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.

 

环境:tomcat5.5.0

            struts.xml信息

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
    xmlns="http://java.sun.com/xml/ns/j2ee
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
         struts.xml 信息:

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
  <include file="struts-default.xml"/>
  <package name="ygn.action" extends="struts-default">
    <action name="HelloWorld" class="ygn.action.HelloWorld">
      <result>HelloWorld.jsp</result>
    </action>
  </package>
</struts>
       SayHello.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Say Hello</title>
</head>
<body>
  <h3>Say "Hello" to :</h3>
  <s:form action="HelloWorld">
    Name:<s:textfield name="name"/>
    <s:submit/>
  </s:form>
</body>
</html>
 

异常分析:以上的配置及文件中,如果采用 http://ip:port/SayHello.jsp,那么会出现前面所提到的异常。如果采用http://ip:port/SayHello.action 进行访问,那么正常。

                     原因:如果想要在jsp文件中,采用 struts的tag,那么必须通过web.xml所配置的过滤器访问文件,否则会有异常,即 之前所出现的异常。

 

解决方案:

       方案一:

              采用 http://ip:port/SayHello.action 访问

      方案二:

             将web.xml 的过滤器,从 *.action 修改为: /*

      方案三:

             修改SayHello.jsp 文件,不使用 struts 的标签。

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yugenning/archive/2008/10/24/3137339.aspx

 

2、No result defined for action and result input

 

这是struts2的一个拦截器报的错误,当你的form中的数据有问题,比如说
<input type="text" name="receiverLoginID" value="<%=name%>"/>
当 name值为NULL时,就出这个错了,所以你可以在当前页面加入以下标签
<div style="color:red">
    <s:fielderror />
</div>
它就会显示拦截器的错误,并在struts的XML中对应action里加如
<result name="input">/AddProducts.jsp</result>
让他把错误返回到该页面就可以了

 

另一种原因:有可能是form的位置或struts1的表示形式不对

 

 3、could not initialize proxy - the owning session was closed

http://hi.baidu.com/birdnic/blog/item/3a27302d9734823c349bf7c1.html

 

关键字: could not initialize proxy - the owning session was closed
开发环境:
Struts 2 + Spring 2.0 + Hibernate 3.2

异常如下:

Java代码
2009-3-21 17:59:05 org.hibernate.LazyInitializationException <init>   
严重: could not initialize proxy - the owning Session was closed   
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed   
     at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)   
     at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)   
     at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)   
     at com.kindion.blog.ArticleType$$EnhancerByCGLIB$$40d67a28.toString(<generated>)   
     at java.lang.String.valueOf(Unknown Source)   
     at java.io.PrintStream.print(Unknown Source)   
。。。。。。。

2009-3-21 17:59:05 org.hibernate.LazyInitializationException <init>
严重: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
 at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:60)
 at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
 at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172)
 at com.kindion.blog.ArticleType$$EnhancerByCGLIB$$40d67a28.toString(<generated>)
 at java.lang.String.valueOf(Unknown Source)
 at java.io.PrintStream.print(Unknown Source)

。。。。。。。

分析原因:
Hibernate 允许对关联对象、属性进行延迟加载,但是必须保证延迟加载的操作限于同一个Session 范围之内进行。如果Service 层返回一个启用了延迟加载功能的领域对象给Web层,当Web层访问到那些需要延迟加载的数据时,由于加载领域对象的Session已经关闭,这些导致了延迟加载数据的访问异常!

 

把所有many-to-one,one-to-one都加上lazy="false"...虽然能解决问题,但并不彻底,还可能影响效率。


Spring 为此提供了一个OpenSessionInViewFilter过滤器,它的主要功能是使每个请求过程绑定一个Session,即使最初的事务已经完成了,也可以在Web层进行延迟加载的操作。

解决方法:(经过查询相关资料,虽然找到这个解决办法,但是我的问题还是没有解决,在此帖出来,希望有人用得着)

在web.xml中配置filter来解决。

Java代码
< filter >   
    < filter-name > hibernateFilter </ filter-name >   
    < filter-class >    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter   
    </ filter-class >   
</ filter >   
  
< filter-mapping >   
    < filter-name > hibernateFilter </ filter-name >   
    < url-pattern > *.action </ url-pattern >   
</ filter-mapping >   

< filter >
   < filter-name > hibernateFilter </ filter-name >
   < filter-class >    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
   </ filter-class >
 </ filter >
 
 < filter-mapping >
   < filter-name > hibernateFilter </ filter-name >
   < url-pattern > *.action </ url-pattern >
 </ filter-mapping >

==================================================================


我的问题解决了,我的问题出现在 web.xml 配置文件下 多个Filter 顺序 的问题


如果你有用到其他的过滤器(Filter),你就把OpenSessionInViewFilter这个过滤器放到你其他过滤器的前面。

Java代码
<!--============SrpingOpenSessionInViewFilter============= -->   
<!--把它放在其他Filter的前面-->   
     <filter>   
<filter-name>hibernateFilter</filter-name>   
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>   
     </filter>   
     <filter-mapping>   
<filter-name>hibernateFilter</filter-name>   
<url-pattern>/*</url-pattern>   
     </filter-mapping>   
<!-- ============Sturts 2 Filter============= -->   
     <filter>   
<filter-name>struts2</filter-name>   
<filter-class>   
     org.apache.struts2.dispatcher.FilterDispatcher   
</filter-class>   
     </filter>   
     <filter-mapping>   
   <filter-name>struts2</filter-name>   
   <url-pattern>/*</url-pattern>   
     </filter-mapping>

还可以参考文章:http://blog.csdn.net/zxd198612/archive/2009/02/13/3886862.aspx

 

4、异常名称  org.hibernate.AssertionFailure
异常消息  null id in entry (don't flush the Session after an exception occurs)

该异常信息是在提示没有为数据中的非空字段设置值。
如果通过Hibernate增加一条记录的时候我们必须显式的通过setXxx方法为该属性赋值(/默认值)。因为在保存之前Hibernate会检查该非空字段对应的实体属性是否为空。
如果不想显式赋值的话,我们可以通过xxx.hbm.xml配置文件来实现,也就是在配置文件中给出该字段的默认值。或者在你的类中设置默认值就行了。
注意的是rename数据库保留字段

 

5、org.apache.jasper.JasperException: Unable to load class for JSP

在jsp页面定义了无用的变量

<input type="hidden" name="jobsort" value="<s:property value='#request.jobsort'>"/>

或者在一个JSP页面中写了如下注释:

<!-- 这里判断userList是否有值过来,也可以用<s:if test="${!empty userList}"> -->

就可能出现此问题

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值