我正在尝试一个简单的Struts2教程,一切正常,“太好了”。这是我的struts.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<package name="default" namespace="/tutorials" extends="struts-default">
<action name="getTutorial" class="org.demian.struts2.tutorial.action.TutorialAction">
<result name="success">/WEB-INF/view/success.jsp</result>
<result name="error">/WEB-INF/view/error.jsp</result>
</action>
</package>
</struts>
这是我的TutorialAction
课程:
package org.demian.struts2.tutorial.action;
public class TutorialAction {
public String execute() {
System.out.println("Hello from execute()!");
return "success";
}
}
这是我的web.xml
:
<?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" 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>Struts2Starter</display-name>
<welcome-file-list>
<welcome-file>/WEB-INF/view/index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我的问题是,如果我在浏览器中写下以下网址:
http://localhost:8080/Struts2Starter/tutorials/asd/getTutorial
我获得了成功页面。这是为什么?即使我写下来,我也会获得成功页面:
http://localhost:8080/Struts2Starter/tutorials/asd/blabla/bla/getTutorial
此映射实际上如何工作?为什么即使我在URL中写废话也能获得成功页面?