java代码:package com.test;import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;import com.opensymphony.xwork2.ActionSupport;@Namespace("/com")
@Action(value = "testStru2", 
results = { @Result(
    name = "success", 
    location = "/hello.jsp") })public class TestStru2Action extends ActionSupport{
public String execute(){
System.out.println("=========");
return SUCCESS;
}

public String test1(){
System.out.println("=========1");
return SUCCESS;
}
}
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>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false"
/> <constant name="struts.devMode" value="false" /> <include
file="example.xml"/> <package name="default" namespace="/"
extends="struts-default"> <default-action-ref name="index" /> <action
name="index"> <result type="redirectAction"> <param
name="actionName">HelloWorld</param> <param
name="namespace">/example</param> </result> </action> </package>
-->
<!-- 开发模式  value设置为true -->
<constant name="struts.devMode" value="true" />
<constant name="struts.configuration.xml.reload" value="true"/> 
<constant name="actionPackages" value="com.test" />
<package name="hello" extends="struts-default">

</package>
</struts>
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>
        <init-param>
         <param-name>actionpackage</param-name>
         <param-value>com.test</param-value>
        </init-param>
    </filter>    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
  <welcome-file-list>
    <welcome-file>hello.jsp</welcome-file>
  </welcome-file-list>
</web-app>
lib:
commons-fileupload-1.2.1.jar,
commons-io-1.3.2.jar,
freeer-2.3.16.jar。
javassist-3.7.ga.jar,
ognl-3.0.jar,
struts2-core-2.2.1.1.jar,
xwork-core-2.2.1.1.jar,
struts2-convention-plugin-2.2.1.1.jar,
struts2-config-browser-plugin-2.2.1.1.jarstruts2   namespace 注解

解决方案 »

  1.   

    @Namespace("/com")
    这一行编译不通过么?
    看你的lib应该包含了,是否build path,讲lib加入到类路径中?
      

  2.   

    @Namespace(value="/com")
    这样呢
      

  3.   

    有用到零配置吗? jar包都没看到,,没有的话,那配置的action 是这个?<action name="index">缺少 class
      

  4.   

    马老师只教了XML配置,不懂注解,唉……。
      

  5.   

    在工程下随便找个地方顶一个一个Namespace类型的变量,看看能否import类进来。如果引用不到,说明你的lib包有问题。如果引入进来了,直接把这个import拷贝到使用注解的那个地方
      

  6.   

    就是要用零配置嘛    但是还需要怎么搞?  搞不懂
    http://www.cnblogs.com/fpjason/archive/2009/08/01/1536671.html
      

  7.   

    都是import进来了哈~~  总感觉还有什么地方没有配置正确    
      

  8.   

    直接在方法上加@action 注解试试
      

  9.   

    都是import进来了哈~~  总感觉还有什么地方没有配置正确    
    import没报错?那怎么会编译不通过呢。。
      

  10.   

    都是import进来了哈~~  总感觉还有什么地方没有配置正确    
    import没报错?那怎么会编译不通过呢。。编译肯定没问题哦~~
    访问的时候找不到
    There is no Action mapped for namespace [/com/test] and action name [testStru2] associated with context path [/testStruts2]. - [unknown location] 
      

  11.   

    都是import进来了哈~~  总感觉还有什么地方没有配置正确    
    import没报错?那怎么会编译不通过呢。。编译肯定没问题哦~~
    访问的时候找不到
    There is no Action mapped for namespace [/com/test] and action name [testStru2] associated with context path [/testStruts2]. - [unknown location] 看到你的错误没?
    There is no Action mapped for namespace [/com/test] 
    说的是没有找到命名空间:/com/test
    而你这个类上面命名空间定义的是:@Namespace("/com")
    明显明明空间对应不上了,怎么能访问呢!
      

  12.   

    都是import进来了哈~~  总感觉还有什么地方没有配置正确    
    import没报错?那怎么会编译不通过呢。。编译肯定没问题哦~~
    访问的时候找不到
    There is no Action mapped for namespace [/com/test] and action name [testStru2] associated with context path [/testStruts2]. - [unknown location] 看到你的错误没?
    There is no Action mapped for namespace [/com/test] 
    说的是没有找到命名空间:/com/test
    而你这个类上面命名空间定义的是:@Namespace("/com")
    明显明明空间对应不上了,怎么能访问呢!
    不是  这个是后面加的   相信我这个低级错误还是不会犯的
      

  13.   

    都是import进来了哈~~  总感觉还有什么地方没有配置正确    
    import没报错?那怎么会编译不通过呢。。编译肯定没问题哦~~
    访问的时候找不到
    There is no Action mapped for namespace [/com/test] and action name [testStru2] associated with context path [/testStruts2]. - [unknown location] 看到你的错误没?
    There is no Action mapped for namespace [/com/test] 
    说的是没有找到命名空间:/com/test
    而你这个类上面命名空间定义的是:@Namespace("/com")
    明显明明空间对应不上了,怎么能访问呢!
    不是  这个是后面加的   相信我这个低级错误还是不会犯的
    那相关使用Action的jsp或配置文件发出来看看呗?