Tuesday, August 29, 2006

Spring MVC and Servlets

I've been using Spring MVC for a variety of web applications. It really does have a lot of nice advantages over Struts making it one of the better request-based frameworks (as opposed to the component based frameworks like Seam.) I came across an interesting use case that doesn't seem to be covered by Spring MVC.

I had a URL mapped to a controller. The URL needed to work for a variety of devices, not just
"full" web browsers like IE and Firefox. In particular it needed to work with a J2ME application. The controller needed to inspect the user agent of the HTTP request, build a model based on this information, and then forward to a view. The view would be different for different devices.

The wrinkle came when the developer working on the J2ME application told me he wanted the view to output a binary data stream. This could be done in a JSP, but is more suited to using a servlet. So I needed to configure a view in Spring MVC that was a servlet.

Spring MVC includes many view implementations. Several JSP-variants, and many other specialized views for working with various technologies such as Jasper Reports, Free Market, POI, PDF, etc. But nothing for a user built servlet like the one I needed to forward to. Seems like kind of a hole in Spring MVC.

Turns out it is not too hard to work around. The key is using the "forward:" prefix. Simply append this to the URL path specified in your servlet mapping, and it will short-circuit the Spring view lookup and forward directly to the desired servlet. So for example, if in your web.xml you had specified "/myServlet" as the mapping to your servlet, then having your controller return something like new ModelAndView("forward:/myServlet", "myModel", model) would forward to your servlet, and allow you to retrieve the model you had built in your controller using a simple request.getAttribute("myModel").

So it was easy to work around, but it still seems like Spring should have a servlet view. Maybe I will try to submit one to them...



technorati tags:,



Blogged with Flock

98 comments:

  1. "Mostly technical and political,the stuff that bores everyone"

    pal,you really wanna tell you're so much different than others..and I think it's too cliche:D

    ReplyDelete
  2. Anonymous2:51 AM

    Thank you! I was wondering how to use it with servlets! Great!

    ReplyDelete
  3. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Digital Marketing Training in Chennai

    Digital Marketing Training in Bangalore

    digital marketing training in tambaram

    digital marketing training in annanagar

    ReplyDelete
  4. Anonymous5:04 AM

    Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    full stack developer training in annanagar

    full stack developer training in tambaram

    full stack developer training in velachery

    ReplyDelete
  5. It would have been the happiest moment for you,I mean if we have been waiting for something to happen and when it happens we forgot all hardwork and wait for getting that happened.

    selenium training in pune

    ReplyDelete
  6. This is ansuperior writing service point that doesn't always sink in within the context of the classroom. In the first superior writing service paragraph you either hook the reader's interest or lose it. Of course your teacher, who's getting paid to teach you how to write an good essay, 
    python training institute in chennai
    python training in Bangalore
    python training institute in chennai

    ReplyDelete
  7. This is very good content you share on this blog. it's very informative and provide me future related information.

    Data Science training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune

    ReplyDelete
  8. I think you have a long story to share and i am glad after long time finally you cam and shared your experience.
    java training in jayanagar | java training in electronic city

    java training in chennai | java training in USA

    ReplyDelete
  9. Anonymous4:53 AM

    Thank you for this post. Thats all I are able to say. You most absolutely have built this blog website into something speciel. You clearly know what you are working on, youve insured so many corners.thanks
    angularjs Training in bangalore

    angularjs Training in btm

    angularjs Training in electronic-city

    angularjs online Training

    angularjs Training in marathahalli

    ReplyDelete
  10. Interesting blog, it gives lots of information to me. Thanks for sharing such a nice blog.

    payrollmanagementservice
    Article submission sites

    ReplyDelete
  11. feeling so good to read your information's in the blog.
    thanks for sharing your ideas with us and add more info.
    german speaking classes in bangalore
    german coaching centers in bangalore
    German Training in Nolambur
    German Training in Ashok Nagar

    ReplyDelete
  12. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
    Java Training in Bangalore
    Java Training Classes in Bangalore
    Java Training Courses in Bangalore
    Best Institute For Java Training In Bangalore

    ReplyDelete
  13. I found your blog while searching for the updates, I am happy to be here. Very useful content and also easily understandable providing.. Believe me I did wrote an post about tutorials for beginners with reference of your blog. 
    best rpa training in bangalore
    rpa training in bangalore | rpa course in bangalore
    RPA training in bangalore
    rpa training in chennai
    rpa online training


    ReplyDelete
  14. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    AWS Training in Bangalore

    AWS Training in pune

    ReplyDelete
  15. Very nice blog. A great and very informative post, Keep up the good work!

    ExcelR Data Science Course in Bangalore


    ReplyDelete
  16. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.
    date analytics certification training courses
    data science courses training

    ReplyDelete
  17. Cool stuff you have and you keep overhaul every one of us
    Data Science Course in Pune

    ReplyDelete
  18. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business.
    data science corse malaysia

    ReplyDelete


  19. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.







    BIG DATA COURSE MALAYSIA

    ReplyDelete
  20. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  21. I'm really impressed with the info you provide in your articles. Hope to see more info from this site

    Inplant Training in Chennai
    Inplant Training
    Inplant Training in Chennai for IT

    ReplyDelete
  22. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!.
    Data Science Courses

    ReplyDelete
  23. Awesome post sir,
    really appreciate for your writing. This blog is very much useful...

    Hi guyz click here Digital Marketing Training in Bangalore to get the best knowledge and details and also 100% job assistance hurry up...!!

    DO NOT MISS THE CHANCE...

    ReplyDelete
  24. Great Posts with very much valuable information. Great post special thanks to the author.
    SAP Training in Chennai | Hardware and Networking Training in Chennai | Pearson Vue Exam Center in Chennai

    ReplyDelete
  25. Very awesome!!! When I seek for this I found this website at the top of all blogs in search engine.
    rpa training in malaysia

    ReplyDelete
  26. This comment has been removed by the author.

    ReplyDelete
  27. Attend The Digital Marketing Course Bangalore From ExcelR. Practical Digital Marketing Course Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Digital Marketing Course Bangalore.
    Digital Marketing Course Bangalore

    ReplyDelete
  28. Study Machine learning course bangalore with ExcelR where you get a great experience and better knowledge.Machine learning course bangalore

    ReplyDelete
  29. Study Machine learning course bangalore with ExcelR where you get a great experience and better knowledge.Machine learning course bangalore

    ReplyDelete
  30. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.
    data science training in gurgaon

    ReplyDelete
  31. Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
    ai training in aurangabad

    ReplyDelete
  32. I read your post and I found it amazing! thank!


    data science course in raipur

    ReplyDelete
  33. Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!
    data science training in noida

    ReplyDelete
  34. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
    ai training in patna

    ReplyDelete
  35. It is perfect time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or tips. Perhaps you could write next articles referring to this article. I want to read more things about it!
    data science training in coimbatore

    ReplyDelete
  36. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.

    Data Science Course

    ReplyDelete
  37. It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.

    Data Science Training

    ReplyDelete
  38. This content is very considered and well-thought. You are a distinctive thinker. You have put up the unique points to bring up specific points. Please continue doing such good work.
    SAP training in Mumbai
    SAP course in Mumbai
    SAP training institute Mumbai

    ReplyDelete
  39. If all the writers who pen down articles would give a thought to write topic specific articles like you, then more number of readers would read their content.
    SAP training in Kolkata
    SAP course in kolkata
    SAP training institute in Kolkata

    ReplyDelete
  40. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    data science institute in ecil

    ReplyDelete
  41. I am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles.
    data science course in hyderabad
    business analytics course in hyderabad
    data analytics course in hyderabad

    ReplyDelete
  42. Personally I think overjoyed I discovered the blogs.pmp certification in malaysia

    ReplyDelete
  43. Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
    360 DigiTMG data analytics courses hyderabad

    ReplyDelete
  44. Amazing post found to be very impressive while going through this post. Thanks for sharing and keep posting such an informative content.

    360DigiTMG Business Analytics Course

    ReplyDelete
  45. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next
    python training in bangalore

    python training in hyderabad

    python online training

    python training

    python flask training

    python flask online training

    python training in coimbatore
    python training in chennai

    python course in chennai

    python online training in chennai


    ReplyDelete
  46. I am really searching for this kind of information, as well as I came to know many things. so please update the latest information, it may be useful for me like beginners.

    Full Stack Course in Bangalore

    Full Stack Training in Hyderabad

    Full Stack Course in Hyderabad

    Full Stack Training

    Full Stack Course

    Full Stack Online Training

    Full Stack Online Course


    ReplyDelete
  47. Really awesome blog!!! I finally found a great post here.I really enjoyed reading this article. Thanks for sharing valuable information.

    We are giving all Programming Courses such as You can

    Register for a free Online Demo Classes

    Data Science Training Institute in Pune
    Best Python Online Training
    Online AWS Training
    Online Data Science Training

    ReplyDelete
  48. This blog is really helpful for me and got a basic knowledge in this topic. Waiting for more updates, kindly keep continuing.

    Machine Learning Training in Hyderabad

    ReplyDelete
  49. great java tips At SynergisticIT we offer the best java training california

    ReplyDelete
  50. Fantastic blog extremely good well enjoyed with the incredible informative content which surely activates the learners to gain the enough knowledge. Which in turn makes the readers to explore themselves and involve deeply in to the subject. Wish you to dispatch the similar content successively in future as well.

    artificial intelligence course in raipur

    ReplyDelete
  51. Awesome blog. I enjoyed reading your articles. This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work! contact us

    ReplyDelete


  52. Nice article and thanks for sharing with us. Its very informative




    Machine Learning Training in Hyderabad

    ReplyDelete

  53. Nice article and thanks for sharing with us. Its very informative




    DATA SCIENCE TRAINING IN HYDERABAD

    ReplyDelete
  54. Im really impressed by it.I am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts. data science training

    ReplyDelete
  55. I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.
    data science training

    ReplyDelete
  56. I am sure that this is going to help a lot of individuals. Keep up the good work. It is highly convincing and I enjoyed going through the entire blog.
    data scientists training

    ReplyDelete
  57. Joining the AI Patasala Best Python Training in Hyderabad program would be a great choice for Python career-minded people.
    Python Institutes in Hyderabad

    ReplyDelete
  58. Thanks for It is informative post .

    SEO Freelancer in Bangalore ,naveedadigital.com offers best SEO freelancing services
    in Bangalore for all kinds of businesses.

    https://naveedadigital.com/
    https://naveedadigital.com/digital-marketing-freelancer-in-bangalore/
    https://naveedadigital.com/social-media-marketing-freelancer-in-bangalore/

    ReplyDelete
  59. This post is so interactive and informative.keep update more information...
    RPA Training in Tambaram
    RPA Training in Chennai

    ReplyDelete
  60. Really impressed! Everything is very open and very clear clarification of issues. It contains true facts. Your website is very valuable. Thanks for sharing.
    data analytics courses in hyderabad with placements

    ReplyDelete
  61. Hi, Thanks for sharing nice articles...

    <a href="https://www.dnaglobal.in”>Best CA Company in india</a>

    ReplyDelete
  62. This post is so interactive and informative.keep update more information…
    SEO Training in Anna Nagar
    SEO Training in Chennai

    ReplyDelete
  63. diploma in digital marketing malaysia3:22 AM

    This post is easy to peruse and acknowledge without forgetting about any subtleties. Extraordinary work! diploma in digital marketing malaysia

    ReplyDelete
  64. thanks due to the fact you have been precise-natured to percentage opinion subsequent to us. we are able to continually recognize all you have finished here because I understand you are selected worried thinking about our.! Users can save their personalized presentations locally and online into their accounts using this software. Prezi Pro Account Hack

    ReplyDelete
  65. i'm able to see which you are an capable at your pitch! i'm launching a internet site quickly, and your inform could be very useful for me.. thanks for all your benefit taking place and wishing you all the triumph for your issue.! Microsoft Office 2010 Cracker

    ReplyDelete
  66. Anonymous6:56 PM

    We current you a extensive selection of good night messages for him that you simply may send. Good Night Wishes For best Friends words and phrases will gladden these people Good Night Messages For Friends

    ReplyDelete
  67. Best AWS Training provided by Vepsun in Bangalore for the last 12 years. Our Trainer has more than 20+ Years
    of IT Experience in teaching Virtualization and Cloud topics.. we are very delighted to say that Vepsun is
    the Top AWS cloud training Provider in Bangalore. We provide the best atmosphere for our students to learn.
    Our Trainers have great experience and are highly skilled in IT Professionals. AWS is an evolving cloud
    computing platform provided by Amazon with a combination of IT services. It includes a mixture of
    infrastructure as service and packaged software as service offerings and also automation. We have trained
    more than 10000 students in AWS cloud and our trainer Sameer has been awarded as the best Citrix and Cloud
    trainer in india.

    ReplyDelete
  68. Get dual certification from IBM and UTM Malaysia with the 360DigiTMG Data Science Certification program.
    data scientist course in chennai

    ReplyDelete
  69. waiting for your next post
    Nice Post...I have learn some new information.thanks for sharing.

    ReplyDelete
  70. If you’re considering pursuing a Master of Business Administration (MBA), enrolling in one of the top MBA colleges in Bangalore is a smart and strategic choice. Known as the Silicon Valley of India, Bangalore is an educational hub with a vibrant culture of innovation that attracts aspiring business professionals. Renowned institutions such as Akash Group of Institutions, Christ University, SBR, Symbiosis Institute, and M.S. Ramaiah College provide exceptional academic programs, state-of-the-art facilities, and a supportive environment that fosters holistic development.

    The leading MBA colleges in Bangalore offer a range of specializations, including finance, marketing, human resources, information technology, leadership, and entrepreneurship, making them ideal for students seeking a diverse and comprehensive MBA experience. These programs equip students with the skills and knowledge needed to excel in today’s competitive business landscape.

    ReplyDelete