0

I am working on struts2-archetype-starter. Got a demo struts 2 project by executing:

mvn archetype:generate -B -DgroupId=demoStrutsStarter -DartifactId=DemoStrutsStarter -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts2-archetype-starter

I modified my struts.xml and added a struts.action.extension constant declaration. Now it looks like this:

<?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>

    <constant name="struts.action.extension" value=","/>
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>

    <package name="myPackage" extends="struts-default">

        <default-action-ref name="index" />

        <action name="index" class="demoStrutsStarter.IndexAction">
            <result>/jsp/index.jsp</result>
        </action>

        <action name="helloWorld" class="demoStrutsStarter.HelloWorldAction">
            <result name="input">/jsp/index.jsp</result>
            <result>/jsp/helloWorld.jsp</result>
        </action>

    </package>

</struts>

But, I am getting a 404 error when I type:

http://localhost:8080/DemoStrutsStarter/index

I am not sure where I am wrong. Can anybody please help me find out why I am unable to call actions without .action extension?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Prakhar Mishra
  • 1,586
  • 4
  • 28
  • 52
  • Is your app working w/o `struts.action.extension`? – Aleksandr M May 20 '14 at 09:18
  • Yes. `http://localhost:8080/DemoStrutsStarter/index.action` always displays the correct page, no matter if `struts.action.extension` is there or not. But, after setting it to ",", it shouldn't. – Prakhar Mishra May 20 '14 at 13:26

2 Answers2

0

Try adding a namespace to your package:

<package name="myPackage" namespace="/" extends="struts-default" >
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • `http://localhost:8080/demo/index` still says `404 Not found` and `http://localhost:8080/demo/index.action` gives me the required form. I am testing it on Jetty: `mvn jetty:run` – Prakhar Mishra May 21 '14 at 04:21
  • Which Struts2 version? – Andrea Ligios May 21 '14 at 07:35
  • Same version which comes along `mvn archetype:generate -B -DgroupId=demoStrutsStarter -DartifactId=DemoStrutsStarter -DarchetypeGroupId=org.apache.struts -DarchetypeArtifactId=struts2-archetype-starter`. How to check? – Prakhar Mishra May 21 '14 at 08:38
  • I found it here `struts.apache.org/release/2.2.x/docs/struts-2-maven-archetypes.html`. **The Starter Archetype** was providing me `spring and sitemesh integration` and i fell for it. Thanks for helping me. – Prakhar Mishra May 21 '14 at 08:52
  • You're right... then let us continue this discussion in the other question – Andrea Ligios May 21 '14 at 08:55
0

Try this out in both results

result 1

<result>/WEB-INF/jsp/index.jsp</result>

result 2

<result>/WEB-INF/jsp/helloWorld.jsp</result>

else check your package name is correct or not. by default, it's name default

try this links. it may help

1.stack overflow link 1

2.link 2 mkyong

3.stack overflow link 3

Community
  • 1
  • 1
Paresh3489227
  • 845
  • 11
  • 22