Joh*_*lly 5 java spring servlets jetty spring-mvc
我已经设置了我的spring-mvc servlet以匹配*.page请求.我已将web.xml中的welcome-file-list设置为index.page
当我转到我的网络服务器的根目录时,这会有效:
http://me.com确实会被正确地重定向到http://me.com/index.page.
但是,当我使用子目录时,它不会重定向:
http://me.com/dashboard并没有重定向到http://me.com/dashboard/index.page
有没有办法让这个映射工作?
我的web.xml文件(摘录):
<welcome-file-list>
<welcome-file>index.page</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.page</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
我的webdefault.xml(来自码头):
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>welcomeServlets</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>redirectWelcome</param-name>
<param-value>false</param-value>
</init-param>
Run Code Online (Sandbox Code Playgroud)
Bal*_*usC 12
本<welcome-file>应代表你想成为每当终端用户请求一个文件夹中的任意文件夹实际存在的文件(如根/,但它也可以是任何其他文件夹,例如/foo/).您只需要了解servletcontainer将在执行转发之前测试其物理存在,如果它不存在,则将返回HTTP 404页面未找到错误.
在您的特定情况下,index.page根文件夹中没有物理文件.实际上index.jsp,根文件夹中有一个文件.这index.page只是一个虚拟URL.因此servletcontainer将无法找到物理index.page文件,因此错误输出404.
您可以通过将index.page文件旁边的物理存在index.jsp文件放在同一文件夹中来欺骗servlet容器来解决此问题.该文件可以保持完全为空.servletcontainer将找到该文件,然后转发到index.page该文件然后将调用控制器servlet,而控制器servlet实际上将为index.jsp视图提供服务.那会很好用的.
| 归档时间: |
|
| 查看次数: |
14123 次 |
| 最近记录: |