当前位置: 代码迷 >> J2EE >> 警告: No configuration found for the specified action: '/HelloWorld'
  详细解决方案

警告: No configuration found for the specified action: '/HelloWorld'

热度:638   发布时间:2016-04-22 01:47:24.0
struts2的配置问题
因为有个项目需要用到Struts2, 所以照着书上的例子从最简单的HelloWorlod学起,可是总是报404找不到网页的错误,找了半天就是不知道什么原因,郁闷了

  首先我的项目名称叫Struts2_HelloWorld,我在项目下的src目录下新建了一个HelloWorld类,如下:


package tutorial;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport
{
  private static final long serialVersionUID = 1L;
  private String name;

  public String getName
  {
  return name;
  }

  public void setName(String name)
  {
  this.name = name;
  }

  public String execute()
  {
  name = "Hello, " + name + "!";

  return SUCCESS;
  }
}

 该目录下还有struts.properties文件和struts2.xml文件

struts.properties文件内容如下:
 
  struts.locale = en_GB

struts2.xml文件内容:

  <!DOCTYPE struts PUBLIC 
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
  <struts>
  <include file="struts-default.xml"/>
  <package name="tutorial" extends="struts-default">
  <action name="HelloWorld" class="tutorial.HelloWorld">
  <result>HelloWorld.jsp</result>
  </action>
  </package>
  </struts>

另外连个jsp文件分别是sayHello.jsp:
  <%@ page language="java" contentType="text/html;charset=gb2312" %>
  <%@ taglib prefix="s" uri="/struts-tags"%>

  <body>
  <h3:>Say "Hello" to:</h3>
  <s:form action="HelloWorld">
  Name:<s:textfield name="name"/>
  <s:submit/>
  </s:form>
  </body>

HelloWorld.jsp文件如下:

 <%@ page language="java" contentType="text/html;charset=gb2312"%>
 <%@ taglib prefix="s" uri="/struts-tags"%>

 <body>
  <h3><s:property value="name"/></h3>
 </body>

我现在浏览器输入http://localhost:8080/Struts2_HelloWorld/sayHello.jsp
  我输入内容提交以后就报404的错误:
  HTTP Status 404 - /Struts2_HelloWorld/HelloWorld

--------------------------------------------

type Status report

message /Struts2_HelloWorld/HelloWorld

description The requested resource (/Struts2_HelloWorld/HelloWorld) is not available.


--------------------------------------------

Apache Tomcat/5.5.20


后台出现两条警告:

信息: Server startup in 7109 ms
2011-4-6 7:35:16 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
警告: No configuration found for the specified action: '/HelloWorld' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2011-4-6 7:35:18 org.apache.struts2.components.Form evaluateExtraParamsServletRequest
警告: No configuration found for the specified action: '/HelloWorld' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

  我在配置文件里面把路径弄了半天还是这个错,真是郁闷了


------解决方案--------------------
我按照你写的再重写一遍:
Action类HelloWorld 代码如下:
Java code
package tutorial;import com.opensymphony.xwork2.ActionSupport;public class HelloWorld extends ActionSupport {    private static final long serialVersionUID = 1L;    private String name;    public String getName {        return name;    }    public void setName(String name){        this.name = name;    }    public String sayHelloWorld(){        name = "Hello, " + name + "!";        return "sayHello";    }}
  相关解决方案