如何在 MVC 的 url 模式中正确使用通配符 (*)
我试图让 servlet 响应每个带有“/test/*” url 模式的请求。所以这个控制器应该响应:
myApp/test/
myApp/test/whatever
myApp/somehting?other=stuff
使用以下映射:
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test/</url-pattern>
</servlet-mapping>
控制器被调用很好,但是转发到视图:
RequestDispatcher view = request.getRequestDispatcher("test.jsp");
view.forward(request,response);
正在生成错误:
超出嵌套请求分派的最大深度
我猜url匹配也发生在转发到视图上?因为它正在经历与传入请求相同的路由过程 - 或者部分?
在 url 模式中使用 * 而不导致这种情况的正确方法是什么?
I am trying to get a servlet to respond to every request with a url-pattern of "/test/*". so this controller should respond to :
myApp/test/
myApp/test/whatever
myApp/somehting?other=stuff
using the following mapping:
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test/</url-pattern>
</servlet-mapping>
The controller is called fine but the forwarding to the view:
RequestDispatcher view = request.getRequestDispatcher("test.jsp");
view.forward(request,response);
is generating an error:
Exceeded maximum depth for nested request dispatches
I guess the url matching happens on forwards to views too? as in it is going through the same routing process as incoming requests - or partly?
what is the correct way to use * in the url-pattern without causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论