简体   繁体   中英

Struts2: Setting constant struts.action.extension to “,” not working

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?

尝试将命名空间添加到您的包中:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM