Results 1 to 4 of 4

Thread: Implementing a simple servlet without a view

  1. #1
    Join Date
    Jul 2007
    Posts
    8

    Default Implementing a simple servlet without a view

    Hi folks,
    I have a question on the use of Dispatcher servlet and need of controllers:
    My application is a simple servelt that receives an http request and based on this calls an update on my database. This servlet does not have any views and does not need an html page. All it needs to do is to get triggered by receiving an http request and perform some actions.

    I have this servlet extending the DispatcherServlet and have overridden the doService method wherein required updates on database is done. I do not have a controller since I do not see the need of it in this case.

    Somehow when sending a http request I get the following error:

    PageNotFound org.springframework.web.servlet.DispatcherServlet noHandlerFound No mapping for [/was/myapplication-web/MyApplicationServlet] in DispatcherServlet with name 'MyApplicationServlet'

    I think I can solve the problem by implementing a controller, but I do not see the need of this. Am I wrong, or is there a way around this?

    Thx, M.K

  2. #2

    Default Re

    maybe you only want to use Spring for configuration or data access, but not as a MVC framework, and still you can. modify your servlet to extend of httpservlet. delete all configuration related to dispatcher servlet and keep the only to apply to the rest of your application. declare the ContextConfigLocation and ContextLoaderListener in the web.xml. in the servlet init method retrieve the beans from the shared context created from ContextLoaderListener.

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    You don't have to use a Controller next to that extending DispatcherServlet for this cause is way to complex.

    Put your logic in a bean which implements HttpRequestHandler, implement the handleRequest method and you are probably done. Configure your DispatcherServlet, map the url to the HttpRequestHandler and presto...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4

    Default

    You can also overwrite FrameworkServlet which is about the bare minimum that still can be configured in the application context but you would have to interpret the url yourself and dispatch to handlers of different url patterns.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •