Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Why dispathcer-servlet.xml can't process p:suffix=".html"?

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm stuck in understanding why my web container keeps displaying the following on the web browser if I simply change the servlet to return pages appending a suffix ".html" instead of ".jsp" which works to begin with.


Here're the relevant sections of my project. The only change that I need to make this work is to change dispatcher-servlet.xml to use p:suffix=".jsp" /> instead of p:suffix=".html" />. In my WEB-INF/jsp folder, I have both index.jsp and index.html. So any idea why it wouldn't work if I ask the viewResolver bean to return html pages?

web.xml


dispatcher-servlet.xml


ProjectController.java
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are mapping *.html to dispatcherservlet in web.xml, so when you change the suffix to .html, it goes and search for the corresponding mapping controller, which is not found.
Map *.htm to your dispatcherservlet in web.xml and you can change the suffix to .jsp or .html, then it should work.
 
Mike Cheung
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi thanks for the reply. Did you mean to say when the controller returns the view page say contacts, the servlet appends .html so it becomes index.html. But because according to web.xml, it needs to intercept all requests with the .html suffix so this returned page (ie index.html) got intercepted again. As such the controller don't know how to handle this loop and therefore spitted out 404.

You suggested to configure web.xml with .htm instead of.html but wouldn't this makes it unable to handle a request with .html suffix?

If what I'm looking for is a way for users to make a request of index.html, and have the controller to return index.html, what is the appropriate way to do this?
 
Mike Cheung
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I found the solution. Turns out I need to do the following.
1) Add the following to dispatcher-servlet.xml and leave the suffix to keep referencing .jsp so the Controller can still return JSP pages if required.


In the end, the file looks like this.


2) Use the following return in the Controller's method.


3) The web.xml file doesn't need to intercept specifically for any URL ending with .html so it looks like this.


If anyone knows of another more appropriate way for doing this, please voice out.
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Cheung wrote:Did you mean to say when the controller returns the view page say contacts, the servlet appends .html so it becomes index.html. But because according to web.xml, it needs to intercept all requests with the .html suffix so this returned page (ie index.html) got intercepted again. As such the controller don't know how to handle this loop and therefore spitted out 404.


Yes. correct, but its not the servlet that appends .html, its the viewResolver you have configured that suffixes the .html and also prefixes /WEB-INF/jsp.

Mike Cheung wrote:You suggested to configure web.xml with .htm instead of.html but wouldn't this makes it unable to handle a request with .html suffix?


Here all the request ending with *.htm will go through the controller and give the requested html. In case you need to serve .html request directly, it would still serve, but not through the controller.
reply
    Bookmark Topic Watch Topic
  • New Topic