Sunday 15 February 2015

Spring not redirecting to html page -



Spring not redirecting to html page -

here view resolver:

<bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/pages/"/> <property name="suffix" value=".html"/> </bean>

i have controller should homecoming hello.html:

@controller @requestmapping("/") public class indexcontroller { @requestmapping(method = requestmethod.get) public string gethtmlpage() { homecoming "hello"; } }

when access localhost:8080 error message:

warning: no mapping found http request uri [/web-inf/pages/hello.html] in dispatcherservlet name 'mvc-dispatcher'

now when alter suffix value .jsp, hello.jsp returned correctly.

<bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <property name="prefix" value="/web-inf/pages/"/> <property name="suffix" value=".jsp"/> </bean>

hello.jsp , hello.html in same folder. ideas how prepare this?

edit:

for html don't need view resolvers. instead create folder in webapp folder. phone call static illustration , add together <mvc:resources mapping="/static/**" location="/static/" /> xml.

in controller instead of return "hello"; set return "static/hello.html";

as complement answers of how map requests html file in spring mvc?, internalresourceviewresolver knows how render jsp or jsp+jstl views. of course of study utilize html views - if makes little sense(*) - writing custom viewresolver able render plain html pages.

(*) normally, controller prepares model used view. in plain html view, cannot utilize model. when seek that, needs redirect plain html page, not utilize view.

to redirect html page, set out of web-inf folder, in place accessible resource.

but in particular need, trying display hello.html root url. best way set straight @ root of web application folder atn declare in welcome-file-list of web.xml :

<welcome-file-list> <welcome-file>hello.html</welcome-file> </welcome-file-list>

spring spring-mvc

No comments:

Post a Comment