Struts2.0的异常
2008-10-24 17:33
381 查看
异常信息: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 的标签。
环境: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 的标签。
相关文章推荐
- 关于在struts2.0中应用json产生类型访问异常问题的解决
- Struts2.0的异常 The Struts dispatcher cannot be found.
- Spring3.0 整合 Struts2.0 出现的异常
- Struts2.0异常总结
- struts2.0中spring配置文件中action的属性 scope="prototype"
- Struts 2.0 整合 Hibernate 3.2 开发注册登录系统
- struts2.0深入理解
- net 2.0 访问Oracle --与Sql Server的差异,注意事项,常见异常
- 运行Struts项目时出现java.lang.reflect.InvocationTargetException异常解决办法
- struts2.0+spring2.0+hibernate3.1 多层模型整合 完整过程 常见错误
- struts2.0 struts.xml type="redirect" 传递参数问题
- struts2.0中struts.xml配置文件详解
- Struts2.0 文件上传与下载全解析
- struts2.0使用中的一个问题
- 【Struts2.0】Struts 2的基石——拦截器(Interceptor)
- Struts2.1XX 后台不打印异常问题
- 在Struts 2.0中实现表单数据校验(Validation)
- .net 2.0 访问Oracle --与Sql Server的差异,注意事项,常见异常
- Struts2.0+spring2.0+hibernate3.2 Annotation应用示例
- Struts2 global-results(全局结果)+异常映射 Results结果类型