<constant name="struts.devMode" …

本文探讨了Struts2框架中开发模式配置引发的问题,特别是关于devMode配置导致的异常,提供了详细的错误堆栈跟踪,并揭示了问题的根本原因是Tomcat安装路径中存在空格。此外,还介绍了Struts2的几个关键配置选项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<constant name="struts.devMode" value="true"/>不能开启
java2010-07-16 16:54:26阅读273评论0  字号:大中小 订阅

1.启动
<constant name="struts.devMode" value="true"/> 或者
<constant name="struts.configuration.xml.reload" value="true"/>
时启动tomcat报错。
org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter struts2
java.lang.NullPointerException
    at com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:209)
    at com.opensymphony.xwork2.util.FileManager.fileNeedsReloading(FileManager.java:60)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.needsReload(XmlConfigurationProvider.java:325)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.needsReload(StrutsXmlConfigurationProvider.java:168)
    at com.opensymphony.xwork2.config.ConfigurationManager.conditionalReload(ConfigurationManager.java:220)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:61)
    at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:774)
    at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:191)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:108)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3709)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4363)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
2009-2-4 22:40:54 org.apache.catalina.core.StandardContext start
严重: Error filterStart
2009-2-4 22:40:54 org.apache.catalina.core.StandardContext start
严重: Context [/Struts2Demo2] startup failed due to previous errors

    devMode模式是开发模式,开启它则默认开启了i18n.reload、configuration.xml.reload。这个错误是由于configuration.xml.reload设置为true倒置的,但是网上的资料没有说明原因及解决办法,倒是一个国外的apache相关BBS上有人说这是216版本的BUG,并且附上了一个.patch修正文件,说217版本会修正。。。可我不会用也不知道是不是这个原因,这个问题就一直搁置在这里了。过了几个月,也就是最近网上查了下发现在apache的一个邮件列表中有关于这个的解释,原因很简单,tomcat的安装路径包含空格。。。无语啊。。。一试果然如此。(PS:刚下了struts2.1.8.1就没这个问题了。版本的事太麻烦了)

   下面是4个开发模式常用配置的简介---
    <!-- 开启使用开发模式,详细错误提示 -->
    <!-- <constant name="struts.devMode" value="true"/>-->
    <!-- 指定每次请求到达,重新加载资源文件 -->
    <!-- <constant name="struts.i18n.reload" value="true"/>-->
    <!-- 指定每次配置文件更改后,自动重新加载 -->
    <!-- <constant name="struts.configuration.xml.reload" value="true"/>-->
    <!-- 指定XSLT Result使用样式表缓存 -->
    <!-- <constant name="struts.xslt.nocache" value="true"/>-->

2.零配置插件codebehind一旦导入就必须进行init-param初始化配置,否则报错:packageAction can't mapping action!

3.<s:i18n name="???"></s:i18n>包住那个标签,该标签就加载它指定的国际化文件,不管是text,textfield还是form都是如此。

4.action实例、xxxScope对象都在ValueStack内,直接使用${}调用

5.使用append标签时,没有所谓的将map和list集合对象连接起来的说法,在创建map对象的使用的语法为#{:,},如果省略冒号,则默认value为null。

5.StackContext 中的对象可以理解为struts2标签库使用的专用对象,比如通过value属性调用:value="#xxx.xxx.xxx..."

6.ValueStack是StackContext的顶级对象,可以不需要#前缀使用,StackContext中的某些已建立对象可以通过比如在某些标签中设置var属性调入根对象ValueStack,达到省略#号的目的。在实际中则可以理解为在标签内临时新建的一个或多个对象,通过var属性指定的名称访问 value="xxx.xxx.xxx...."

7.${requestScope.xxx.name} 与 <s:property value="#request.xxx.name"/>(escapse属性设置为false) 表达的内容相同,都是输出request范围内的xxx对象的name属性值,且无论是否该值包含html代码

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?> &lt;!-- /* * $Id: struts-plugin.xml 722219 2008-12-01 20:41:26Z musachy $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * &quot;License&quot;); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ --> &lt;!DOCTYPE struts PUBLIC &quot;-//Apache Software Foundation//DTD Struts Configuration 2.5//EN&quot; &quot;http://struts.apache.org/dtds/struts-2.5.dtd&quot;> &lt;struts> &lt;bean class=&quot;com.inc.sbu.view.FreeMarkerPageFilter&quot; static=&quot;true&quot; optional=&quot;true&quot;/> &lt;constant name=&quot;struts.ognl.allowStaticMethodAccess&quot; value=&quot;true&quot; /> &lt;constant name=&quot;struts.convention.relative.result.types&quot; value=&quot;freemarker,dispatcher&quot;/> &lt;constant name=&quot;struts.convention.action.mapAllMatches&quot; value=&quot;true&quot;/> &lt;constant name=&quot;struts.convention.package.locators&quot; value=&quot;web,action&quot; /> &lt;constant name=&quot;struts.convention.default.parent.package&quot; value=&quot;yk-default&quot;/> &lt;constant name=&quot;struts.convention.result.path&quot; value=&quot;/pages&quot;/> &lt;constant name=&quot;struts.convention.result.flatLayout&quot; value=&quot;true&quot;/> &lt;constant name=&quot;struts.i18n.encoding&quot; value=&quot;gbk&quot; /> &lt;constant name=&quot;struts.i18n.reload&quot; value=&quot;false&quot; /> &lt;constant name=&quot;struts.devMode&quot; value=&quot;false&quot; /> &lt;constant name=&quot;struts.serve.static.browserCache&quot; value=&quot;false&quot;/> &lt;constant name=&quot;struts.configuration.xml.reload&quot; value=&quot;false&quot; /> &lt;constant name=&quot;struts.custom.i18n.resources&quot; value=&quot;globalMessages&quot; /> &lt;constant name=&quot;struts.freemarker.manager.classname&quot; value=&quot;customFreemarkerManager&quot; /> &lt;constant name=&quot;struts.multipart.saveDir&quot; value=&quot;/tmp&quot;/> &lt;constant name=&quot;struts.multipart.maxSize&quot; value=&quot;1000000000&quot; /> &lt;constant name=&quot;struts.ui.theme&quot; value=&quot;simple&quot;/> &lt;constant name=&quot;struts.action.extension&quot; value=&quot;xhtml,,json&quot; /> &lt;constant name=&quot;struts.enable.DynamicMethodInvocation&quot; value=&quot;true&quot;/> &lt;package name=&quot;yk-default&quot; extends=&quot;struts-default&quot;> &lt;result-types> &lt;result-type name=&quot;jasper&quot; class=&quot;org.apache.struts2.views.jasperreports.JasperReportsResult&quot;/> &lt;result-type name=&quot;json&quot; class=&quot;org.apache.struts2.json.JSONResult&quot;/> &lt;/result-types> &lt;interceptors> &lt;interceptor class=&quot;com.inc.sbu.struts.AuctionInterceptor&quot; name=&quot;auctionInterceptor&quot;/> &lt;interceptor class=&quot;com.inc.sbu.struts.TokenInterceptor&quot; name=&quot;incTokenInterceptor&quot;/> &lt;interceptor class=&quot;com.inc.sbu.struts.WorkFlowInterceptor&quot; name=&quot;incFlowInterceptor&quot;/> &lt;interceptor class=&quot;com.inc.sbu.util.FileUploadInterceptor&quot; name=&quot;fileUploadInterceptor&quot;/> &lt;interceptor class=&quot;com.inc.sbu.struts.ClewInterceptor&quot; name=&quot;clewInterceptor&quot;/> &lt;interceptor-stack name=&quot;bidStack&quot;> &lt;interceptor-ref name=&quot;exception&quot;/> &lt;interceptor-ref name=&quot;alias&quot;/> &lt;interceptor-ref name=&quot;servletConfig&quot;/> &lt;interceptor-ref name=&quot;prepare&quot;/> &lt;interceptor-ref name=&quot;profiling&quot;/> &lt;interceptor-ref name=&quot;staticParams&quot;/> &lt;interceptor-ref name=&quot;actionMappingParams&quot;/> &lt;interceptor-ref name=&quot;params&quot;> &lt;param name=&quot;excludeParams&quot;>dojo\..*,^struts\..*&lt;/param> &lt;/interceptor-ref> &lt;interceptor-ref name=&quot;conversionError&quot;/> &lt;interceptor-ref name=&quot;auctionInterceptor&quot;/> &lt;/interceptor-stack> &lt;interceptor-stack name=&quot;subStack&quot;> &lt;interceptor-ref name=&quot;exception&quot;/> &lt;interceptor-ref name=&quot;alias&quot;/> &lt;interceptor-ref name=&quot;servletConfig&quot;/> &lt;interceptor-ref name=&quot;i18n&quot;/> &lt;interceptor-ref name=&quot;prepare&quot;/> &lt;interceptor-ref name=&quot;chain&quot;/> &lt;interceptor-ref name=&quot;profiling&quot;/> &lt;interceptor-ref name=&quot;scopedModelDriven&quot;/> &lt;interceptor-ref name=&quot;fileUploadInterceptor&quot;/> &lt;interceptor-ref name=&quot;fileUpload&quot;/> &lt;interceptor-ref name=&quot;checkbox&quot;/> &lt;interceptor-ref name=&quot;staticParams&quot;/> &lt;interceptor-ref name=&quot;actionMappingParams&quot;/> &lt;interceptor-ref name=&quot;params&quot;> &lt;param name=&quot;excludeParams&quot;>dojo\..*,^struts\..*&lt;/param> &lt;/interceptor-ref> &lt;interceptor-ref name=&quot;conversionError&quot;/> &lt;interceptor-ref name=&quot;validation&quot;> &lt;param name=&quot;excludeMethods&quot;>input,inputxy,back,cancel,browse&lt;/param> &lt;/interceptor-ref> &lt;interceptor-ref name=&quot;clewInterceptor&quot;> &lt;param name=&quot;excludeMethods&quot;>login,loginManager,logout,index&lt;/param> &lt;/interceptor-ref> &lt;interceptor-ref name=&quot;incTokenInterceptor&quot;/> &lt;/interceptor-stack> &lt;/interceptors> &lt;default-interceptor-ref name=&quot;subStack&quot;/> &lt;global-results> &lt;result name=&quot;invalid.token&quot;>/pages/error/repeat-submit.jsp&lt;/result> &lt;result name=&quot;clew&quot; type=&quot;dispatcher&quot;>/pages/clew.jsp&lt;/result> &lt;result name=&quot;manage-clew&quot; type=&quot;dispatcher&quot;>/pages/manage-clew.jsp&lt;/result> &lt;result name=&quot;auction-clew&quot; type=&quot;dispatcher&quot;>/pages/auction-clew.jsp&lt;/result> &lt;result name=&quot;syserror&quot; type=&quot;dispatcher&quot;>/pages/error.jsp&lt;/result> &lt;result name=&quot;validerror&quot; type=&quot;dispatcher&quot;>/pages/error.jsp&lt;/result> &lt;result name=&quot;frontpurviewerror&quot; type=&quot;dispatcher&quot;>/pages/error/frontpurviewerror.jsp&lt;/result> &lt;result name=&quot;frontloginerror&quot; type=&quot;dispatcher&quot;>/pages/error/frontpurviewerror.jsp&lt;/result> &lt;result name=&quot;fronterror&quot; type=&quot;dispatcher&quot;>/pages/error/frontticketerror.jsp&lt;/result> &lt;result name=&quot;filenotfound&quot; type=&quot;dispatcher&quot;>/pages/error/filenotfound.jsp&lt;/result> &lt;result name=&quot;login&quot; type=&quot;redirect&quot;>/login&lt;/result> &lt;result name=&quot;adminLogin&quot; type=&quot;dispatcher&quot;>/login.jsp&lt;/result> &lt;result name=&quot;login&quot; type=&quot;redirect&quot;>/login&lt;/result> &lt;result name=&quot;entran&quot; type=&quot;redirect&quot;>/entran&lt;/result> &lt;!-- &lt;result name=&quot;adminLogin&quot; type=&quot;dispatcher&quot;>/login.jsp&lt;/result> --> &lt;result name=&quot;auctionAdminError&quot; type=&quot;redirect&quot;>/auction/adminLogin&lt;/result> &lt;result name=&quot;auctionActorError&quot; type=&quot;redirect&quot;>/auction/login&lt;/result> &lt;/global-results> &lt;/package> &lt;!-- Overwrite Convention --> &lt;/struts> 我现在需要重写fileUpload,即不再使用fileUpload的拦截器,需要怎么配置
最新发布
08-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值