1

我是 Struts2 的新手。我试图执行一个简单的 Struts2 程序。显然我struts.xml没有调用该动作。

Server returned http response code 407 for url: "http://struts.apache.org/dtds/struts-2.1.7.dtd在我的struts.xml.

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">

 <struts>
   <package name="default" extends="struts-default">
      <action name="hello" class="com.FirstStruts.ExampleStruts" method="execute">
            <result name="success">/Helloworld.jsp</result>
      </action>
   </package>

 </struts>

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" 
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   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>Struts 2</display-name>
   <welcome-file-list>
      <welcome-file>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>

Action:

package com.FirstStruts;

public class ExampleStruts {
    private String f_name;
    private String l_name;

    public String execute() throws Exception {
        System.out.println("Hello. in execeute");
        return "success";   
    }

    public String getF_name() {
        return f_name;
    }

    public void setF_name(String f_name) {
        this.f_name = f_name;
    }

    public String getL_name() {
        return l_name;
    }

    public void setL_name(String l_name) {
        this.l_name = l_name;
    }


}

当我尝试执行时,我收到了错误There is no Action mapped for namespace / and action name ExampleStruts.

我正在使用http://www.nabisoft.com/tutorials/struts2/basic-struts2-project-setup中提到的罐子

你能帮我吗?

4

1 回答 1

1

你的动作被称为hello, no ExampleStruts,所以它不会找到它。更改您的struts.xml文件:

<action name="ExampleStruts" class="com.FirstStruts.ExampleStruts">
    <result>/Helloworld.jsp</result>
</action>

或在您的index.jsp.

此外,您需要从 扩展您的操作ActionSupport,因此它将被识别为一个操作。

于 2013-06-11T09:37:44.433 回答