当前位置: 代码迷 >> Java Web开发 >> Struts2 为何总提示“The requested resource (/struts2qs/Test) is not available.”?该怎么处理
  详细解决方案

Struts2 为何总提示“The requested resource (/struts2qs/Test) is not available.”?该怎么处理

热度:339   发布时间:2016-04-17 01:01:22.0
Struts2 为何总提示“The requested resource (/struts2qs/Test) is not available.”?
目录结构如下: 
根目录在 D:/Tomcat 6.0/webapps/Struts2 
index.jsp: D:/Tomcat 6.0/webapps/Struts2/index.jsp 
web.xml: D:/Tomcat 6.0/webapps/Struts2/WEB-INF/web.xml 
struts.xml: D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.xml 
TestAction.class D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/TestAction.class 

web.xml: 
<?xml version="1.0" encoding="GBK"?>
<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">


<!-- 定义Struts2的FilterDispathcer的Filter -->
  <filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  </filter>

<!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>


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

index.jsp 

<%@ page language="java" contentType="text/html; charset=GBK"%>
<html>
<head>
<title>登录页面</title>
</head>
<body>
<form action="Test" method="get">
<input type="submit" value="Test"/>
</form>
</body>
</html>

index.jsp可以正常显示,但是点击Test按钮会出现错误: 
type Status report

message /struts2qs/Test

description The requested resource (/struts2qs/Test) is not available.


------解决方案--------------------
struts.xml 
<?xml version="1.0" encoding="GBK"?> 
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
"http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<package name="lee" extends="struts-default"> 
<action name="Test" class="TestAction"> 
<result name="success">welcome.jsp </result> 
</action> 
</package> 
</struts> 
配置中class需要加上包名的啊
------解决方案--------------------
你的action路径错了
把你那个package的name属性去掉就ok了
action后面加上.action
  相关解决方案