2014-05-19 15 views
0

我正在致力於struts2-archetype-starter。通過執行了一個演示struts 2項目:Struts2:將常量struts.action.extension設置爲「,」不起作用

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

我修改了struts.xml,並增加了struts.action.extension常量聲明。現在,它看起來像這樣:

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

但是,我得到一個404錯誤,當我鍵入:

http://localhost:8080/DemoStrutsStarter/index 

我不知道我在哪裏錯了。任何人都可以請幫我找出爲什麼我無法通過.action擴展名稱進行操作?

+0

是否正在使用您的應用程序W/O'struts.action.extension'? –

+0

是的。無論'struts.action.extension'是否存在,'http:// localhost:8080/DemoStrutsStarter/index.action'總是顯示正確的頁面。但是,在設置爲「,」之後,它不應該。 –

回答

0

嘗試增加一個命名空間到你的包:

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

'http:// localhost:8080/demo/index'仍然表示'404 Not found'和'http:// localhost:8080/demo/index.action'爲我提供了必要的表單。我在Jetty上測試它:'mvn碼頭:運行' –

+0

哪個Struts2版本? –

+0

與mvn archetype相同的版本:generate -B -DgroupId = demoStrutsStarter -DartifactId = DemoStrutsStarter -DarchetypeGroupId = org.apache.struts -DarchetypeArtifactId = struts2-archetype-starter'。如何檢查? –