0

运行 URL ( http://localhost:8080/Jasper/myJasperTest.action ) 时,错误消息中的操作名称为空。即使我通过引用其他stackoverflow Q也找不到问题。如果你们中的一个人能帮助我解决这个问题,我真的很感激。下面提到了我的项目源代码以及我的控制台错误消息。谢谢。

Error Message 
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [] associated with context path [/Jasper].

    Dec 27, 2015 3:30:49 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
SEVERE: Exception occurred during processing request: There is no Action mapped for namespace [/] and action name [] associated with context path [/Jasper].
There is no Action mapped for namespace [/] and action name [] associated with context path [/Jasper]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:534)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

strutsjasper.xml

<struts>

<package name="default" namespace="/" extends="jasperreports-default">
    <action name="myJasperTest" class="com.acme.test.action.JasperAction">
        <result name="success" type="jasper">
            <param name="location">/jasper/our_compiled_template.jasper</param>
            <param name="dataSource">myList</param>
            <param name="format">PDF</param>
        </result>
    </action>

</package>
</struts>

Web.xml

<display-name>Struts2Jasper</display-name>`<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>


</welcome-file-list>`


<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>

<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping> 

JasperAction 类

public class JasperAction extends ActionSupport {

/** 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(
                "S2_WEBAPP/jasper/our_jasper_template.jrxml",
                "S2_WEBAPP/jasper/our_compiled_template.jasper");
    } catch (Exception e) {
        e.printStackTrace();
        return ERROR;
    }

    return SUCCESS;
}

public List<Person> getMyList() {
    return myList;
}
}

Person class
public class Person {

private Long id;

private String name;

private String lastName;

public Person() {
}

public Person(String name, String lastName) {
    this.name = name;
    this.lastName = lastName;
}

public Person(Long id, String name, String lastName) {
    this.id = id;
    this.name = name;
    this.lastName = lastName;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

public String getLastName() {
    return lastName;
}

public void setLastName(String lastName) {
    this.lastName = lastName;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}}

我的 Jrxml 位于 WebContent/S2_WEBAPP/jasper/

4

0 回答 0