日期:2014-05-19  浏览次数:20638 次

Struts2初学者 求助
尚学堂马士兵 视频配套的代码
Struts2_0100_Introduction
就是Struts2的HelloWorld的代码
很简单 就是一个 hello.jsp而已
我记得昨天还能试验程序正常打开网页的。
但是现在只能打开Tomcat的首页,其他的所有页面都跳The requested resource (/Struts2_0100_Introduction/hell) is not available. 这类错误。
奇怪的是 唯独我今天用来复习巩固的project里面定义的welcome-file能够打开。真是想不明白 到底哪里错了。
我的Project代码如下 请好心人帮忙看下
web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name></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>

Struts.xml:
<?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.enable.DynamicMethodInvocation" value="false" /> -->
  <constant name="struts.devMode" value="ture" />

  <package name="relationship" namespace="/relationship" extends="struts-relationship">
  <action name="/friend" >
  <result>/Friend.jsp</result>
  </action>
  </package> 
  <package name="relationship1" namespace="/" extends="struts-relationship1">
  <action name="index" >
  <result>/index.jsp</result>
  </action>
  </package> 


  <!-- Add packages here -->

</struts>

输入http://localhost:8080/BlloseWorld/的时候是可以正常访问index.jsp
输入http://localhost:8080/BlloseWorld/relationship/friend时候报错:

type Status report

message There is no Action mapped for action name friend.

description The requested resource (There is no Action mapped for action name friend.) is not available.

------解决方案--------------------
There is no Action mapped for action name friend

Java code
<action name="/friend" >
  <result>/Friend.jsp</result>
  </action>

------解决方案--------------------
又看见了楼主类似的帖子,建议楼主先不要创新,先把视频中源码的脉络累清。
1、输入http://localhost:8080/BlloseWorld/的时候是可以正常访问index.jsp
这个其实找的是<welcome-file>index.jsp</welcome-file>中的jsp,没有执行struts。xml里东西
2、http://localhost:8080/BlloseWorld/relationship/friend
<action name="/friend" >里面不应该加“/”,而且应该是你没有配置对应friend的class类,错误说的很明白,There is no Action mapped for action name friend。