日期:2014-05-20  浏览次数:20741 次

struts2 报错.action is not available
本来是好的,后来恢复系统后,原来的工程有的地方就出错了(虽然是在D盘,但还是丢失了一些工程需要的jar包,这些jar包引自D盘,这也是没想明白的地方,为什么恢复系统D盘的东西会丢)。
现在的问题是没有出错的工程也运行不了了。
是struts2最简单的例子,jar包都检查了没问题。tomcat刚刚重装,在系统变量中classpath中添加了tomcat的lib。
报错:
type Status report

message /test/WebRoot/hello.action

description The requested resource (/test/WebRoot/hello.action) is not available.
工程用<Context>和直接放在tomcat的webapp下都不行。
第一个页面index.jsp可以正常显示,点击“进入”就提示上述错误。
工程目录确定没错!
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
xwork-2.0.3.jar
struts2-core-2.0.8.jar
这些包是恢复系统之前用的都可以成功运行。只要后五个包,但听有人说前两个也要,但是不管前俩有没有都不行。
恢复系统应该没对工程有多少影响,应该考虑tomcat(刚刚重装,显示基本页面没用问题)?或者系统的别的地方有影响工程运行的??请高手帮忙!

代码:
index.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
  <head>
<title>index</title>
  </head>
  
  <body>
<a href="hello.action">进入</a>
  </body>
</html>
---------------------------------------------------------------

struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="wutao" extends="struts-default">
<action name="hello" class="test.TestAction">
<result name="success">
/hello.jsp
</result>
</action>
</package>
</struts>
-------------------------------------------------------------------

action:
package test;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class TestAction extends ActionSupport {
private String message = "hello word";

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

@Override
public String execute() throws Exception {
return SUCCESS;
}
}

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

hello.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
  <head>
  <title>My JSP 'fuck.jsp' starting page</title>
  </head>
  
  <body>
  <s:property value="message"/>

  </body>
</html>
======================================================================================================







------解决方案--------------------
<package name="wutao" extends="struts-default"> 还有其他struts.xml文件?
------解决方案--------------------
(/test/WebRoot/hello.action)
怎么会跳到WebRoot下?
------解决方案--------------------
你struts.xml里的package不是wutao么,路径应该是/wutao/hello.action啊。
------解决方案--------------------
struts.xml中继承 struts-default.xml 中的struts-default
<struts name="struts2" extends="struts-default">