`
liulanghan110
  • 浏览: 1063970 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

关于web.xml的首页和struts的action的问题

阅读更多

wel.xml是这样配置的:

<welcome-file-list>
	<welcome-file>index.action</welcome-file>
</welcome-file-list>

 struts是这样配置的:

<action name="index" >
            <result type="redirectAction">index_view</result>
    	</action>
    	<action name="index_*" class="com.syspro.action.IndexAction" method="{1}">
    		<result name="success" >/template/index.ftl</result>
    	</action>

 我开始这样以为的,当访问项目的URL时(http://127.0.0.1:8080/test/),tomcat会根据web.xml中欢迎文件的配置自动在URL后加上index.action。而这个url会被struts拦截,所以会转向IndexAction,最后会转向index.ftl文件。

但实际是,这样的配置会报资源没找到的错误。

 

解决办法是在根目录下创建一个index.action(要与web.xml中的欢迎页面相同)文件。为什么湿这样子的呢?

因为tomcat加载web.xml时,会找所配置的欢迎页面是否存在,不存在则报错。注意,此时并没有URL被请求。而上面的情况就是,当tomcat找index.action这个文件时,没找到,所以报错了。所以根本没有请求url。而当在根目录下加一个index.action时,因为找到了文件,所以不会报错。然后 tomcat继续加载其他文件,当文件加载完时,开始请求这个URL(http://127.0.0.1:8080/test/index.action),以便打开欢迎页面。当请求这个URL时,这个URL被struts拦截,转向action处理,从而index.action文件没被打开。所以无论index.action填的什么,都不会显示。

 

另外,按照web.xml的配置, struts会拦截所有的URL,所以无论index.action的后缀是action还是别的什么,都可以转向到index的action。单实际上却不是如此,为什么呢?

 

因为struts.xml中有这个struts.action.extension ,设置struts要处理的action的。

一般可以设置成 这样:

<constant name="struts.action.extension" value="do,action" />

 

如果不设置呢,就默认为action。所以上面的例子只有后缀为你配置的struts.action.extension中的后缀时才成功。

 

 

分享到:
评论
1 楼 yz_zhouwt 2012-07-22  
谢谢,今天也遇到同样的问题。

相关推荐

    struts.xml和applicationContext.xml、web.xml的配置

    struts.xml和applicationContext.xml、web.xml的配置

    Struts in Action中文版

    2.6.2. Struts的强项........................................................................................................58 Struts in Action 中文版 Lastest Revised:10/14/2005 10:27:00 AM ...

    Struts2项目开发流程简明实例

    功能: ...  否则页面跳转到login.jsp页面等待用户输入;  此实例只适合对Struts2不了解的初学者. 工具:Eclipse+Tomcat 技术:Jsp,Struts2 ...6. 创建struts.xml配置Action 7. 部署和运行struts2项目

    struts in Action

    1.1. 关于本书...............................................................................................................19 1.1.1. 谁创建了Struts?......................................................

    一个struts2的例子:彻底解决STRUTS2 错误There is no Action mapped for namespace / and action name login

    再声讨下struts2,为什么要在框架里面加载一个死的struts.xml,难得不能想struts1 一样的在web.xml里面配置吗? 看网上都催struts2比struts1 整的整的好,我看就这个问题,完全可以算struts2是个垃圾 我现在把完整...

    从零开始创建基于struts1.2 + Hibernate3.0的Web工程

    4.4. 添加formbean和actionbean .......................................11 4.5. 添加menu画面....................................................13 5. 调试工程..............................................

    struts2的rest风格插件实例

    通过 struts.xml、struts.properties 或 web.xml 改变 struts.convention.default.parent.package 常量的值,让支持 REST 风格的 Action 所在的包默认继承 rest-default,而不是继承默认的 convention-default 父包...

    J2EE电子商务系统开发从入门到精通

    2.6.1 web.xml文件..... 38 2.6.2 Struts-config.xml文件..... 39 2.7 Struts标签库..... 43 2.7.1 Bean标签库..... 43 2.7.2 HTML标签库..... 44 2.7.3 Logic标签库..... 45 2.8 Struts开发环境搭建..... 46 2.8.1 ...

    struts自我学习过程程序以及说明

    配置dwr.xml和web.xml 运行 http://localhost:5858/start/dwr/ 它会在后台输出一些信息,自己看一下就可以了,就是一些加载项之类的东西或者是其他的一些信息. ajaxvalidate包 AjaxValidation.jsp 配置struts.xml即可...

    第一个struts程序

    1、login.jsp的form表格里的action是在struts.xml中&lt;action name="login" class="check.action.LoginAction"&gt;的name的属性的名字后面加上.action 例如:&lt;form action="login.action" method="post"&gt; 2、web.xml中 ...

    Struts2教程

    由于 Struts 的入口点是 ActionServlet ,所以得在 web.xml 中配置一下这 个 Servlet 。 2. 编写 Action 类(一般从 org.apache.struts.action.Action 类继承)。 3. 编写 ActionForm 类(一般从 org.apache.struts....

    struts2 和Srping 2.5 整合的测试简单例子

    配置文件 web.xml applicationContext.ml struts.xml Action 类 LoginAction spirng 处理类 LoginServiceImpl 实现LoginService接口

    struts2+spring+hibernate整合示例

    b 在struts.xml中添加action,使用通配符的方式 , 注意这里和单独struts2不同的地方: class属性指向的是bean 的 id ,这里我们配置bean采用spring ioc注解的方式, 所以默认的bean的id 为 类名(首字母小写) ...

    整合struts2和spring源代码(可以直接在tomcat中运行)

    1.将struts2和spring中的库文件复制到项目下(可以查看WEB-INF\lib目录下的文件) 注意:struts2-spring-plugin-2.3.8.jar和commons-logging.jar文件可以在 struts框架中的找到而spring.jar 在spring框架中 2. ...

    struts2+spring2+ibates

    4、写sping的application和applicationservices或者其它配置.(可对些文件分为其它文件,在web.xml中注册即可) 5、配置struts.xml 6、配置sqlmapconfig.xml,如果有include,则配置其它文件. 7、写dao和service类. 8、...

    struts2 action 配置方法 &&struts2的配置文件

    struts2 action几乎完全吸收了xwork 的精华,近日学习struts 2,总结...struts2相关的配置文件有web.xml(必须的),struts.xml(必须的),struts.properties,struts-default.xml,velocity.properties,struts-default.vm。

    Struts2最新漏洞升级2.3.32版本

    3、修改 WEB-INF\classes 目录下struts.xml 文件,加上: &lt;constant name="struts.enable.DynamicMethodInvocation" value="true"/&gt; &lt;constant name="struts.convention.action.mapallmatches" value="true"/&gt; 这...

    struts2课件

    struts2课件 很好的struts2当输入login.jsp访问jsp页面填写完相关信息并提交给login.action时,它会首先被在web.xml中配置的过滤器监听到,过滤器会去查找strust.xml文件,并结合namespace查找名为login的action,...

    Struts2入门教程(全新完整版)

    十二、总结 本教程对struts2的基本知识进行了一些说明,关于struts2的更多详细内容应参看struts2的官方文档及提供的app实例。 下面对struts2的基本执行流程作一简要说明,此流程说明可以结合官方提供的struts2结构图...

    struts-2.3.4.1所需的jar文件

    web.xml &lt;filter-name&gt;struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter &lt;filter-name&gt;struts2 &lt;url-pattern&gt;/* struts.xml &lt;?xml version="1.0" ...

Global site tag (gtag.js) - Google Analytics