Announcement Announcement Module
Collapse
No announcement yet.
Popup Static HTML page Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Popup Static HTML page

    Hi,

    I have configured dispatcher servlet as below
    Code:
      <servlet>
      	<servlet-name>dispatcher</servlet-name>
      	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      	<load-on-startup>1</load-on-startup>
      </servlet>
      
      <servlet-mapping>
      	<servlet-name>dispatcher</servlet-name>
      	<url-pattern>*.html</url-pattern>
      </servlet-mapping>
    This is my view resolver
    Code:
    <bean id="viewresolver"
    		class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    		p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    Now, i got a requirement to popup dynamic generated HTML page. My directory structure is as below.
    Code:
    > WebContent
       > docs
          > generated html
       > WEB-INF
          > JSP
             > common
                > all jsp pages
              ..........
    Now when i tried to open http://localhost:8084/myProject/docs/generatedHTML.html
    view resolver is looking for jsp page and return 404.

    If i change url-pattern of dispatcher servlet it works. But as i have already implement the most of the project i don't want to change in the all controllers.

    Is there any way in SPRING to bypass the view resolver and it will look for html? or any other solution?

    Please help.

    Thanks,
    Ankur

  • #2
    One way of achieving your goal is to set the response type to "text/html" and then write the contents of your dynamically generated HTML file to response outputstream. By this way you can force the browser to render the generated HTML page

    Comment


    • #3
      Thanks for the reply. I didn't understand exactly your solution.

      My problem exactly is that when i tried to access HTML page
      http://localhost:8084/myProject/docs/generatedHTML.html
      according to view resolver it tries to look HTML page at
      /WEB-INF/jsp/docs/generatedHTML.jsp

      but actually it is HTML and outside of WEB-INF. Hope it will help you to understand better.

      Comment


      • #4
        Anks_ce,
        If you are in a situation where in your dynamically generated HTML has to be shown as a response after some processing (request) then you can just read the contents of HTML file in your code into byte[] and write that into response's outputstream by setting the content type to "text/html". Some what like this in your controller

        Code:
        public ModelAndView getHTMLFile(HttpServletRequest request, HttpServletResponse response)
        {
        byte[] arrFileContents = someManager.getHTMLFileContents();//You have read the file into an array of bytes
        response.setContentType("text/html");//Browser will by default try to render the HTML page
        response.getOutputStream().write(arrFileContents);
        .......
        }
        And If you are in a situation where in your end user will enter that URL to access the outside sitting 'generatedHTML.html' file then you can try to chain the view resolvers by setting 'order' property suitably. I hope this will solve the issue though I've never tried this approach nor have come across your situation. Here is the reference also this

        Comment

        Working...
        X