无法从struts2调用servlet

时间:2019-03-26 10:09:34

标签: java servlets struts2

我正在使用Crystal Report Viewer,其中查看器调用servlet操作来显示报告。而且我集成了使用struts2并在后端休眠的用户管理。现在,当我打电话给Crystal Report Viewer动作出错时,该动作未映射在struts2中,但该动作已映射在web.xml文件中的servlet中。我正在共享我的web.xml和struts.xml文件。请建议我如何在struts2中调用servlet动作。

错误:

41057 [http-nio-8080-exec-1] WARN  org.apache.struts2.dispatcher.Dispatcher  - Could not find action or result
There is no Action mapped for namespace / and action name CrystalReportViewerHandler. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:177)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)

如果我不使用struts2,那么查看器动作会完美运行,但是当我集成struts2逻辑时,就会出现异常。

我已经尝试过在struts.xml中使用以下代码,但无法正常工作。

<constant name="struts.action.excludePattern" value="CrystalReportViewerHandler"/>

web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!-- <web-app id="WebApp_ID" 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"> -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>CrystalReport</display-name>
  <context-param>
        <param-name>crystal_image_uri</param-name>
        <param-value>/crystalreportviewers</param-value>
    </context-param>
    <context-param>
        <param-name>crystal_image_use_relative</param-name>
        <param-value>webapp</param-value>
    </context-param>
    <servlet>
        <servlet-name>CrystalReportViewerServlet</servlet-name>
        <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CrystalReportViewerServlet</servlet-name>
        <url-pattern>/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>
  <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>
  <listener>
    <listener-class>com.xyz.scheduling.Listener</listener-class>
  </listener>

  <welcome-file-list>
    <welcome-file>redirect.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Struts.xml

<!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.action.excludePattern" value="CrystalReportViewerHandler"/>
    <action name="reportViwer" method="execute" class="com.xyz.abc.ReportMail">
            <param name="reportId"></param>
            <result name="success">/Pages/Open-Report-viewer.jsp</result>           
        </action>
</package>
</struts>

期望“ CrystalReportViewerHandler”操作有效。

1 个答案:

答案 0 :(得分:0)

过滤器在servlet之前执行。您已将所有传入请求映射到S2筛选器,因此它尝试执行,无法执行并失败。

S2文档涵盖了这一点-我建议您阅读它。简介文档中几乎总是涵盖此类问题。

https://struts.apache.org/core-developers/web-xml.html#exclude-specific-urls

TL; DR:

<struts>
    <constant name="struts.action.excludePattern" value=".*unfiltered.*,.*\.nofilter"/>
    ...

</struts>
相关问题