1

我正在尝试将 Struts 与 Spring 集成。单独的 Struts 工作正常。然而,当我试图把

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation"
            value="/WEB-INF/lib/WebApplicationSpringContext.xml" />
    </plug-in>
    <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />

侧struts-config.xml中的元素,xml开始抛出

The content of element type "struts-config" must match "(data-sources?,form-beans?,global-exceptions?,global-
 forwards?,action-mappings?,controller?,message-resources*,plug-in*)".

以下是我的 struts-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>


    <form-beans>
        <form-bean name="userForm"
            type="com.sample.form.UserForm" />
    </form-beans>

    <action-mappings>

    <action path="/user" type="com.sample.action.UserAction"
            name="userForm" scope="request" validate="true">
            <forward name="success" path="/WEB-INF/jsp/welcome.jsp" />
            <forward name="failed" path="/WEB-INF/jsp/user.jsp" />
        </action>

    </action-mappings>

<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
        <set-property property="contextConfigLocation"
            value="/WEB-INF/lib/WebApplicationSpringContext.xml" />
    </plug-in>

    <controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor" />

</struts-config>

以下是 WebApplicationSpringContext.xml

<?xml version="1.0" encoding="UTF-8" ?>

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/jdbc
        http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd      
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

    <beans:bean name="/user" id="user"
        class="com.sample.action.UserAction">
        <beans:constructor-arg index="0" value="sample" />
    </beans:bean>

</beans:beans>

我被 struts-config.xml 卡住了。先谢谢了。任何建议都将受到欢迎。

4

2 回答 2

2

元素类型“struts-config”的内容必须匹配“(data-sources?,form-b​​eans?,global-exceptions?,global-forwards?,action-mappings?,controller?,message-resources*,plug-in *)”。

尝试放置:

<controller processorClass=...

以上:

<plug-in className="

意思是切换标签顺序

于 2013-05-02T10:03:32.387 回答
1

尝试这个:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>actionbean</display-name>
  <welcome-file-list>
    <welcome-file>welcome.html</welcome-file>    
  </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>



  <servlet>
        <servlet-name>servlet</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>       
        <init-param>
            <param-name>debug</param-name>
            <param-value>2</param-value>
        </init-param>       
        <init-param>
            <param-name>detail</param-name>
            <param-value>2</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>  

    <servlet-mapping>
        <servlet-name>servlet</servlet-name>
        <url-pattern>*.do</url-pattern>
   </servlet-mapping>




    <jsp-config>
        <taglib>
            <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>

        <taglib>
            <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>

          <taglib>
            <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
            <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
        </taglib> 
    </jsp-config>
</web-app>

我假设您在构建路径中有所有正确的 jar 文件。

于 2020-05-08T13:43:28.810 回答