tribbloid
tribbloid

Reputation: 3838

How to return an html file using Spring MVC controller

I'm working on a website using both WaveMaker and Springsource MVC.

The entry generated by WaveMaker is named 'index.html'. I import all browser-side code into the /view directroy of an MVC project. And try to configure ContextLoadListener to map it into an uri. Using:

@RequestMapping(value = "/index", method = RequestMethod.GET)
public String testIndex() {

    return "index.html";
}

Then I got the following error testing it:

SEVERE: PWC6117: File "C:\glassfish3\glassfish\domains\domain1\eclipseApps\TribblesDashboard\WEB-INF\views\index.html.jsp" not found

How do I fix it?

Upvotes: 0

Views: 11286

Answers (1)

Usha
Usha

Reputation: 1468

This can be due to two reasons.

  1. The declaration of view resolver in application context. This should be some thing like this:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

This indicates that the views should be placed in the WEB-INF/jsp folders.

  1. The second is to check the Dispatcher Servlet configuration in the web.xml.
<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

Check if the mappings are OK.

Upvotes: 2

Related Questions