使用 spring mvc 设置默认的 jsp 视图 [英] Setting the default jsp view with spring mvc
问题描述
我想将我的 jsps 文件夹中的一个 jsp 文件设置为应用程序的默认视图.有什么办法可以在 <welcome-file-list>
中告诉 abc.jsp
需要是默认的,并且可以在某某路径中找到它.url 模式也是 html,所以有没有办法在 Spring MVC 中映射它.
I want to set one of jsp files in my jsps folder as the default view for the application. Is there any way we can tell in <welcome-file-list>
that abc.jsp
needs to be default and it can be found in such and such path. Also the url pattern is html so is there a way it can be mapped in Spring MVC.
例如 - 当用户输入 www.example.com
时,我希望应用程序定向到 abc.jsp
页面,并且当有人输入 www 时.example.com/something
,即使这样,应用程序也应该指向 abc.jsp
,但不应该破坏 url 模式.
For example - When a user types www.example.com
, I want the application to direct to abc.jsp
page and also when someone types www.example.com/something
, even then application should direct to abc.jsp
, but the url pattern shouldnt be compromised.
推荐答案
添加
<mvc:view-controller path="/" view-name="abc"/>
到配置文件.然后 ROOT 将解析为 abc 视图.然后添加
to the config file. Then the ROOT will resolve to the abc view. Then add
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
到配置文件.这会将视图解析为/WEB-INF/view/abc.jsp.
to the config file. This will resolve the view to /WEB-INF/view/abc.jsp.
这篇关于使用 spring mvc 设置默认的 jsp 视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!