当前位置: 代码迷 >> Java Web开发 >> Struts2 为啥总提示“The requested resource () is not available.”
  详细解决方案

Struts2 为啥总提示“The requested resource () is not available.”

热度:5694   发布时间:2013-02-25 21:09:29.0
Struts2 为何总提示“The requested resource () is not available.”?
Struts2 为何总提示“The requested resource () is not available.”?

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
  org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
  </filter>
  
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>


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="default" extends="struts-default">
<action name="HelloWorld" 
class="org.sunxin.struts2.ch02.action.HelloWorldAction">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>




HelloWorldAction.java

package org.sunxin.struts2.ch02.action;

import com.opensymphony.xwork2.Action;

public class HelloWorldAction implements Action {

private String message;
public String getMessage(){
return message;
}
public String execute() throws Exception {
message="Hello world!";
return SUCCESS;
}

}




HelloWrold.jsp

<%@page contentType="text/html;charset=gbk"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head><title>欢迎页面</title>
<body>
<h2><s:property value="message"/></h2>
</body>
</html>






------解决方案--------------------------------------------------------
经过测试楼主的写的 是完全可以正确运行的
不知道楼主的项目文件所放位置是否正确,请见图片


红色区域是需要注意的地方 特别是struts.xml文件的位置
------解决方案--------------------------------------------------------
up ,代码没问题
  相关解决方案