Announcement Announcement Module
Collapse
No announcement yet.
Implementing a simple servlet without a view Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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...

      Comment


      • #4
        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.

        Comment

        Working...
        X