Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 即使在xml文件中定义了操作,也无法获取任何操作_Java_Xml_Struts2 - Fatal编程技术网

Java 即使在xml文件中定义了操作,也无法获取任何操作

Java 即使在xml文件中定义了操作,也无法获取任何操作,java,xml,struts2,Java,Xml,Struts2,我最近设置了一个示例项目,在该项目中,我定义了操作,但仍然没有得到任何操作错误。正如您可以在struts2.xml中看到的,已经定义了名为login的操作 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xs

我最近设置了一个示例项目,在该项目中,我定义了操作,但仍然没有得到任何操作错误。正如您可以在struts2.xml中看到的,已经定义了名为login的操作

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>StrutsLoginDemoApp</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <filter>
        <filter-name>struts</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts</filter-name>
        <url-pattern>/action/*</url-pattern>
    </filter-mapping>

    <!-- session config -->
    <session-config>
        <session-timeout>15</session-timeout>
    </session-config>

    <!-- for restricting direct access of jsp pages -->
    <!-- <security-constraint>
        <web-resource-collection>
            <web-resource-name>block_jsp_pages</web-resource-name>
            <url-pattern>*.jsp</url-pattern>
        </web-resource-collection>
        <auth-constraint />
    </security-constraint> -->

</web-app>

StrutsLoginDemoApp
index.jsp
支柱
org.apache.struts2.dispatcher.ng.filter.strutspreadexecutefilter
支柱
/行动/*
15

Struts2路由配置位于名为
struts.xml
的文件中,而不是
Struts2.xml
,这可能是您的问题

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

<struts>

    <!-- removing action extension -->
    <constant name="struts.action.extension" value="" />
    <!-- enabling developer mode -->
    <constant name="struts.devMode" value="true" />

    <package name="default" extends="struts-default"
        namespace="/action">
        <!-- declarartion of interceptor -->
        <interceptors>
            <interceptor name="authenticationInterceptor"
                class="com.demo.interceptor.AuthenticationInterceptor">
            </interceptor>
            <interceptor-stack name="secureStack">
                <interceptor-ref name="authenticationInterceptor" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>

        <action name="login">
            <result>/login.jsp</result>
        </action>

        <action name="loginAction" class="com.demo.action.UserLoginAction">
            <result name="success" type="redirectAction">
                <param name="actionName">task</param>
                <param name="namespace">/action</param>
            </result>
            <result name="login">/login.jsp</result>
        </action>

        <action name="logout" class="com.demo.action.UserLogoutAction">
            <result name="success" type="redirectAction">
                <param name="actionName">login</param>
                <param name="namespace">/action</param>
            </result>
        </action>

        <action name="task">
            <interceptor-ref name="secureStack" />
            <result>/task.jsp</result>
            <result name="login">/login.jsp</result>
        </action>

    </package>


</struts>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Welcome to the Struts2 App</h1><br>
<a href="action/login">Login</a>
</body>
</html>