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">
 
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/application-context.xml</param-value>
    </context-param>    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
 <filter>
        <filter-name>struts-cleanup</filter-name>
        <filter-class>
               com.jasperreport.test.SetCharacterEncodingFilter
        </filter-class>
    </filter>
    
    <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>*.action</url-pattern>
    </filter-mapping>
 
  <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.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>
    <constant name="struts.i18n.encoding" value="UTF-8"/> 
<package name="default" extends="struts-default,jasperreports-default">
    <result-types>
    <result-type name="jasper" class="org.apache.struts2.views.jasperreports.JasperReportsResult"/>
</result-types>

   
    <action name="jasperTest" class="com.jasperreport.test.JasperReportAction">
        <result name="success" type="jasper">
            <param name="location">/our_compiled_template.jasper</param>
            <param name="dataSource">myList</param>
            <param name="format">PDF</param>
        </result>
    </action>
</package>
</struts>访问:http://localhost:8080/testJR/jasperTest.action报错:HTTP Status 404 - There is no Action mapped for namespace / and action name jasperTest.哪里出问题了?

解决方案 »

  1.   

    com.jasperreport.test.JasperReportAction中的代码可能出现了问题,请仔细检查下,看看是不是逻辑上的问题........
      

  2.   

    jasperTest  貌似要写成  /jasperTest
      

  3.   

       <action name="jasperTest" class="com.jasperreport.test.JasperReportAction">
    这里的配置有问题
      

  4.   


    代码逻辑问题不应该报404吧,com.jasperreport.test.JasperReportAction代码都还没执行
      

  5.   


    有什么问题?你是说应该写成<action name="/jasperTest" class="com.jasperreport.test.JasperReportAction">?试了下,还是不行
      

  6.   

    <package name="default" extends="struts-default,jasperreports-default">
    可以多继承吗?
      

  7.   

    出现这个问题的因素很多的...............1.action在加载后丢失......2.action中的某一成员不能预加载......3.配置文件在分析过程中出现错误........4.配置的时候<result>配置错误........很多很多...
      

  8.   

    能帮具体看看吗?
    com.jasperreport.test.JasperReportActionimport java.util.ArrayList;
    import java.util.List;import net.sf.jasperreports.engine.JasperCompileManager;import com.opensymphony.xwork2.ActionSupport;public class JasperReportAction extends ActionSupport {
    /**
     * 
     */
    private static final long serialVersionUID = -2597695688476513241L;
    /** List to use as our JasperReports dataSource. */
        private List<Person> myList;    public String execute() throws Exception {        // Create some imaginary persons.
            Person p1 = new Person(new Long(1), "Patrick", "Lightbuddie");
            Person p2 = new Person(new Long(2), "Jason", "Carrora");
            Person p3 = new Person(new Long(3), "Alexandru", "Papesco");
            Person p4 = new Person(new Long(4), "Jay", "Boss");        // Store people in our dataSource list (normally they would come from a database).
            myList = new ArrayList<Person>();
            myList.add(p1);
            myList.add(p2);
            myList.add(p3);
            myList.add(p4);        // Normally we would provide a pre-compiled .jrxml file
            // or check to make sure we don't compile on every request.
            try {
                JasperCompileManager.compileReportToFile(
                        "testJR/our_jasper_template.jrxml",
                        "testJR/our_compiled_template.jasper");
            } catch (Exception e) {
                e.printStackTrace();
                return ERROR;
            }        return SUCCESS;
        }    public List<Person> getMyList() {
            return myList;
        }
    }
      

  9.   

    <package name="default" extends="struts-default,jasperreports-default" namespace="/">
      

  10.   

    问题找到,是struts.xml文件位置问题。要保证让struts.xml发布后是在classes目录下。
    所有可以直接把struts.xml放在src目录
    或者配置myeclipse,指定发布目标目录