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

MyEclipse中Struts2找不到action
web .xml页面代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">

<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.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd">
   
  <struts>
  <package name="struts2" extends="struts-default">
  <action name="helloworld" class="com.test.action.HelloWorld">
  <result name="success">/helloworld.jsp</result>
  </action>
 
 
  <action name="login" class="com.test.action.loginAction">
  <result name="success">/result.jsp</result>
  </action>
 
 
  </package>
  </struts>

HelloWorld.java页面代码:

package com.test.action;

public class HelloWorld
{
  public String execute()throws Exception
  {
return "success";
  }
}


helloworld.jsp页面代码:

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>My JSP 'helloworld.jsp' starting page</title>
   
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">  
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
  Hello World
  </body>
</html>



为什么最后结果不是Hello World而是提示错误:
HTTP Status 404 - /struts2/helloworld.action

type Status report

message /struts2/helloworld.action

description The requested resource (/struts2/helloworld.action) is not available.
Apache Tomcat/6.0.30

------解决方案--------------------
login 的访问是正常的吗? 是不是发布的问题
------解决方案--------------------
重新部署试试,还有就是看jsp是不是放置在webRoot下面的。
------解决方案--------------------