1

I am trying out a simple Struts2 tutorial and everything works fine, "too much fine". This is my 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>

This is my TutorialAction class:

package org.demian.struts2.tutorial.action;

public class TutorialAction {
    public String execute() {
        System.out.println("Hello from execute()!");
        return "success";
    }
}

And this is my 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>

My problem is that if I write the following URL in the browser:

http://localhost:8080/Struts2Starter/tutorials/asd/getTutorial

I get the Success page. Why is that? I get the success page even if I write:

http://localhost:8080/Struts2Starter/tutorials/asd/blabla/bla/getTutorial

How does this mapping actually work? Why do I get success page even though I write nonsense in the URL?

Ariel
  • 1,222
  • 2
  • 14
  • 25

0 Answers0