• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1251
  • Last Modified:

How can we configure that all the request should pass through dispatcher servlet except a single request which goes to a servlet defined in web.xml.

Hi,

How can we configure that all the request should pass through dispatcher servlet except a single request which goes to a servlet defined in web.xml.

I have configured in web.xml file the below code which dispatches the request to the spring dispatcher servlet.

<servlet-mapping>
&#9;&#9;<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
&#9;&#9;<url-pattern>/</url-pattern>
&#9;</servlet-mapping>


Below is the servlet code which i want to receive a particular request

<servlet-mapping>
&#9;&#9;<servlet-name>CrystalReportViewerServlet</servlet-name>
&#9;&#9;<url-pattern>/CrystalReportViewerHandler</url-pattern>
&#9;</servlet-mapping>
0
Rocking
Asked:
Rocking
  • 3
  • 2
  • 2
  • +2
1 Solution
 
gudii9Commented:
I believe Servlet Filter can help you in this scenario.
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I believe the above configuration that you have posted should work. Is it not? Is there any error messages or further detail that you are able to provide us?
0
 
Sathish David Kumar NArchitectCommented:
<servlet-mapping>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <url-pattern>/</url-pattern>
      </servlet-mapping>

Open in new window


Add servlet class it will work
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
RockingAuthor Commented:
what i actually doing is configuring the crystal report in spring.
Whole application is working fine with the correct entry for dispatcher servlet. the url is something like below

http://localhost:8080/projectname/

but when i click on the crystal report viewer which handles the servlet "CrystalReportViewerServlet" the url is like below.

http://localhost:8080/CrystalReportViewerServlet

The problem is when Report call the servlet CrystalReportViewerServlet, the spring dispacher don't find it so how I can make spring dispacher to call a default servlet that is declare on my Web.xml.

what i need is DispatcherServlet to redirect to the CrystalReportViewerServlet.




Web.xml file is given below





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

      <display-name>GMCS Web Application</display-name>

      <!-- - Loads the root application context of this web app at startup. -
            The application context is then available via - WebApplicationContextUtils.getWebApplicationContext(servletContext). -->

      <context-param>
            <param-name>crystal_image_uri</param-name>
            <param-value>resources/crystalreportviewers</param-value>
      </context-param>
      
                  <context-param>
            <param-name> </param-name>
            <param-value>/CrystalReportViewerHandler</param-value>
            </context-param>
 <!--       <context-param>
            <param-name>crystal_image_use_relative</param-name>
            <param-value>webapp</param-value>
      </context-param>
 -->
      <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:application-context.xml</param-value>
      </context-param>


      <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>

      <!-- - Publishes events for session creation and destruction through the
            application - context. Optional unless concurrent session control is being
            used. -->


      <!-- Reads request input using UTF-8 encoding -->
      <filter>
            <filter-name>characterEncodingFilter</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                  <param-name>encoding</param-name>
                  <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                  <param-name>forceEncoding</param-name>
                  <param-value>true</param-value>
            </init-param>
      </filter>

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



      <!-- Session time out is defined for the application -->
      <session-config>
            <session-timeout>30</session-timeout>
      </session-config>

      <!-- Handles all requests into the application -->
      
      <servlet-mapping>
            <servlet-name>CrystalReportViewerServlet</servlet-name>
            <url-pattern>/CrystalReportViewerHandler</url-pattern>
      </servlet-mapping>
      
      <servlet>
            <servlet-name>CrystalReportViewerServlet</servlet-name>
            <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
      </servlet>
      
      <servlet>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value>
                        /WEB-INF/spring/appServlet/servlet-context.xml
                  </param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
            <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
            <url-pattern>/</url-pattern>
      </servlet-mapping>
      
      <welcome-file-list>
            <welcome-file>/welcome.jsp</welcome-file>
      </welcome-file-list>

      <error-page>
            <error-code>400</error-code>
            <location>/WEB-INF/views/errors/pageNotFound.jsp</location>
      </error-page>

      <error-page>
            <error-code>404</error-code>
            <location>/WEB-INF/views/errors/pageNotFound.jsp</location>
      </error-page>

      <error-page>
            <error-code>403</error-code>
            <location>/WEB-INF/views/errors/accessDeniedPage.jsp</location>
      </error-page>

      <error-page>
            <error-code>500</error-code>
            <location>/WEB-INF/views/errors/errorPage.jsp</location>
      </error-page>

</web-app>
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
With that web.xml configuration, if you access the rest of your app via the...

http://localhost:8080/projectname/

URL, then for your Crystal Reports, you would have to use a URL such as...

http://localhost:8080/projectname/CrystalReportViewerHandler

(Note that "projectname" is in there)

This is something that I see people get confused about quite a bit (I struggled with it too, early on). Think about it heirarchically, you have a "host:port" that identifies your Tomcat instance, then you have a "context" name which identifies which (or possibly many) webapps that are loaded into yout Tomcat instance, and then you have a "servlet" name which (can) identify that servlet within your webapp with your Tomcat instance that you are targetting.

So with the URL for the Crystal Reports that you posted above, you are missing the "context" part of the above, or in other words, it it trying to find the default servlet in a webapp called "CrystalReportViewerHandler" which obviously doesn't exist. You need to target your "projectname" webapp first, and then the "CrystalReportViewerHandler" servlet inside that webapp.


Hope that makes things clearer!
0
 
Sathish David Kumar NArchitectCommented:
Use spring security to move one project  another project.

your link says its diffrent project .

http://localhost/projectName 
http://localhost:8080/CrystalReportViewerServlet

if its not diffrent project  use @mccarl suggestion
0
 
RockingAuthor Commented:
Thanks experts for your valuable suggestion,but i understand that i need to modify the web,xml file to provide the context path otherwise it would not work.
Bu the time i pass the context path i am able to view the report earlier also,but couldn't go to the next page or other except the initial or say first page.

Please refer the below link

http://stackoverflow.com/questions/9680548/how-to-customize-crystal-servlet-uri

Hope so u can get my question clearly.

What i need is there anyway i can bypass the dispatcher request to avoid looking in context and directly in the webapp location for this particular request (CrystalReportViewerHandler).

I am badly stuck in this..
0
 
mrcoffee365Commented:
web.xml does not have a lot of logic associated with it, so you can't use web.xml to do precisely what you're asking.

However, several of the experts have explained other methods.  Leave web.xml with the rule to send all requests to the same dispatcher servlet.  Then put a filter in your web app which recognizes the CrystalReport request and direct it to the servlet you want.

Or, list every single url for your webapp, and send one to the CrystalReport servlet, and the rest to your dispatcher servlet.
0
 
RockingAuthor Commented:
@mrcoffee365

Thanks a lot for suggesting an idea.

"Then put a filter in your web app which recognizes the CrystalReport request and direct it to the servlet you want."



Could u please provide some url or example with respect to above
0
 
mrcoffee365Commented:
This is a pretty good tutorial on how to use a filter in tomcat:
http://viralpatel.net/blogs/tutorial-java-servlet-filter-example-using-eclipse-apache-tomcat/

You don't have to worry about the eclipse part unless you are using eclipse.

In your case, you would check to see if the url matches your CrystalReport url, and in that case forward to the specific servlet, otherwise let it fall through to its normal url.

Writing filters is considered fairly advanced.  If you are not very experienced with tomcat, servlets, etc., you might want to look at tools for doing url rewriting in tomcat, such as the Tuckey url rewriter:
http://tuckey.org/urlrewrite/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now