0

I am using crystal report viewer where viewer call servlet action to display the report. And I integrated user management which is using struts2 and hibernate at backend. Now when I call the crystal report viewer action getting error that action is not mapped in struts2, but that action is mapped in servlet in web.xml file. I am sharing below my web.xml and struts.xml file. please advice how I can call servlet action in struts2.

error:

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)

If I am not using struts2 then viewer action work perfectly but when I integrate struts2 logic then getting exception.

I already tried below code in struts.xml but can not work.

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

web.xml file

<?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>

expecting "CrystalReportViewerHandler" action would work.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Amit Jha
  • 23
  • 1
  • 8

1 Answers1

0

Filters execute before servlets. You've mapped all incoming requests to the S2 filter, so it attempts to execute, cannot, and fails.

The S2 documentation covers this--I'd recommend reading it. Questions like this are almost always covered in the intro documentation.

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

TL;DR:

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

</struts>
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Thank you for your reply, I found the issue after debugging. Actually my struts2 jar was not compatible to handle constant tag but after updating struts2 jar now issue resolve and working fine. – Amit Jha Mar 27 '19 at 04:00