Code Bye

[]Struts2 使用Json 已引入 Json-plugin

报错信息
Tomcatlog
严重: Exception starting filter struts2
Unable to load configuration. - [unknown location]
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:502)
	at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
	at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
	at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:424)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:115)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
	at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1429)
	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.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:297)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:762)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:631)
	at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:568)
	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.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:295)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:762)
	at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1454)
	at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:74)
	at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1295)
	at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1387)
	at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:818)
	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 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303)
	at sun.rmi.transport.Transport$1.run(Transport.java:159)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at java.lang.Thread.run(Thread.java:662)
Caused by: Unable to load configuration. - [unknown location]
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
	at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
	at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
	... 46 more
Caused by: Parent package is not defined: json-default - [unknown location]
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildPackageContext(XmlConfigurationProvider.java:670)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:519)
	at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:292)
	at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
	at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:250)
	at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
	... 48 more

Web.xml

<filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>struts-default.xml,struts-plugin.xml,struts/struts-*.xml</param-value>
        </init-param>
    </filter>

struts-default.xml

        <interceptors>
            <interceptor name="login" class="com.crm.controller.util.LoginInterceptor"></interceptor>
            <interceptor-stack name="loginCheck">
                <interceptor-ref name="login"></interceptor-ref>
                <interceptor-ref name="defaultStack"></interceptor-ref>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="loginCheck"></default-interceptor-ref>
        <global-results>
            <result name="login" type="redirect">/login.jsp</result>
        </global-results>
        <action name="loginAction" class="loginActionBean">
            <result name="SUCCESS">/index.jsp</result>
            <result name="FAIL">/login.jsp</result>
        </action>
        <action name="regAction" class="regActionBean">
            <result name="SUCCESS">/com/crm/function/cust_register.jsp</result>
            <result name="FAIL">/com/crm/function/cust_register.jsp</result>
        </action>
        <action name="showAllCust" class="showAllCustBean">
            <result name="SUCCESS"  type="redirect">/com/crm/function/show_cust.jsp</result>
            <result name="FAIL">/com/crm/function/show_cust.jsp</result>
        </action>
        <action name="custCheck" class="custCheckBean">
            <result name="SUCCESS"  type="redirect" >showAllCust.action</result>
        </action>
        <action name="accessCtrl" class="accessCtrlBean"  >
            <result name="SUCCESS">/com/crm/function/access_ctrl.jsp</result>
        </action>
        <action name="regAction" class="regActionBean" method="execute">
            <!-- 动态设置savePath的属性值 -->
            <result name="SUCCESS">/com/crm/function/cust_register.jsp</result>
            <result name="FAIL">/com/crm/function/cust_register.jsp</result>
            <interceptor-ref name="fileUpload">
                <!-- 文件过滤 -->
                <param name="allowedTypes">image/bmp,image/png,image/gif,image/jpeg,image/jpg</param>
                <!-- 文件大小, 以字节为单位 -->
                <param name="maximumSize">20971520</param>
            </interceptor-ref>
            <!-- 默认拦截器必须放在fileUpload之后,否则无效 -->
            <interceptor-ref name="defaultStack"/>
        </action>
    </package>
    <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
    <constant name="struts.i18n.encoding" value="UTF-8"/>
    <!-- 设置浏览器能否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
    <constant name="struts.serve.static.browserCache" value="false"/>
    <!-- 当struts的配置文件修改后,系统能否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
    <constant name="struts.configuration.xml.reload" value="true"/>
    <!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->
    <constant name="struts.devMode" value="true"/>
    <!-- 默认的视图主题 -->
    <constant name="struts.ui.theme" value="simple"/>
    <constant name="struts.objectFactory" value="spring"/>
    <!-- 文件上传 配置 -->
    <!-- 指定允许上传的文件最大字节数。默认值是2097152(2M) -->
    <constant name="struts.multipart.maxSize" value="20971520"/>
    <!-- 设置上传文件的临时文件夹,默认使用javax.servlet.context.tempdir
    <constant name="struts.multipart.saveDir " value="d:/tmp" />  -->
    <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest"
          name="myRequestParser" class="com.ermsuite.common.fileUpload.RequestParseWrapper"
          scope="default" optional="true" />
    <constant name="struts.multipart.handler" value="myRequestParser" />
    <!-- 引入其他配置文件        -->
    <include file="struts/struts-json.xml"/>
    <!-- 该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即全部匹配*.action的请求都由Struts2处理。
假如用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。 -->
    <constant name="struts.action.extension" value="action"/>

struts-json.xml

 <package name="json" namespace="/jsonspace" extends="json-default">
        <action  name="searchData" class="showDataBean">
            <result type="json" />
                <param name="root">dataMap</param>
        </action>
    </package>

解决方案

100

可能是缺少 struts2-json-plugin-版本.jar 包。
Struts2 是以插件的形式加载 JSON 的,先确认这个 JAR 包能否已经成功导入。
或可以用 GSON 试试,用 GSON 的话,一个包 gson.jar 搞定。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明[]Struts2 使用Json 已引入 Json-plugin