1

I am trying to display the page as .jsp instead of .html in the url but I run into issues. Any ideas or help would be great appreciate.

Everything is working fine with .html

  1. In the tridion, i save my page as index2.jsp. it's using page template which have jsp extension.
  2. I updated the web.xml to have
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.jsp</url-pattern>
  1. updated page controller
@RequestMapping(value = { "/**/*.jsp","/**/*.html", "/**/*.txt", "/**/*.xml" }, method = { GET })

It throws error when i go to ../index.html or /indexjsp.jsp. If i remove the section in web.xml then it works fine

Did i do something wrong or missed anything? any suggestions would be great appreciate.

Thanks

Here is the error:

at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168) at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244) at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:720) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466) at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318) at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)

3
  • 1
    Maybe this helps? stackoverflow.com/questions/16166387/… (or this: forum.spring.io/forum/spring-projects/web/…)
    – Nuno Linhares
    Commented Jul 8, 2016 at 15:47
  • Hi Nuno, Thanks for your help. I tried what they suggested and it still does not work but it
    – Jon S
    Commented Jul 11, 2016 at 13:15
  • 1
    Hi Nuno, Thanks for your help. I tried what they suggested and it still does not works. I think that is for the older Tomcat. I use the Tomcat version 8 so it's already set in conf/web.xml. I put this in the web.xml of my app <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>/WEB-INF/views/*</url-pattern> <url-pattern>*.jsp</url-pattern> </servlet-mapping> Since I remove <url-pattern>*.jsp</url-pattern> in <servlet-name>dispatcher</servlet-name> it does not shows the error anymore but the index2.jsp still does not dispatch.
    – Jon S
    Commented Jul 11, 2016 at 13:22

1 Answer 1

2

The reason this is happening is that you are sending all JSP files through the dispatcher. The dispatcher then finds the RequestMapping attribute on the PageContoller and lets it try to handle the request.

This means that when Spring MVC requests a View, instead of being allowed to load the View, it is treated like a webpage. The PageController tries to resolve it from Tridion, instead of allowing the ViewResolver to load it from the file-system.

In order of execution:

  1. You request /index.jsp, which is handled by the PageController
  2. PageController (and subsequent method calls) determine the Page Template required is /WEB-INF/views/homepage.jsp
  3. /WEB-INF/views/homepage.jsp is requested, as the associated Page Template, which is also (mistakenly) handled by the PageController due to greedy regex
  4. Request for /WEB-INF/views/homepage.jsp returns a 404 as no such Page is published from Tridion

Instead, do the following:

In web.xml before your dispatcher servlet-mapping add the following, to send View requests to the View folder(s)

<servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>/WEB-INF/views/*</url-pattern>
</servlet-mapping>

On your PageController specify the RequestMapping to handle the extensions you need

@RequestMapping(value = { "/**/*.jsp", "/**/*.html", "/**/*.txt", "/**/*.xml" }, method = { GET })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.