Spring MVC附加上下文路径以形成动作 [英] Spring MVC appending context path to form action

查看:94
本文介绍了Spring MVC附加上下文路径以形成动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Spring 3.1下可以很好地运行相同的代码.刚升级到3.2,现在出现以下问题:

Was running same code fine under Spring 3.1. Just upgraded to 3.2 and now the following issue occurs:

<form:form id="customerLoginForm" commandName="customerLoginForm" action="/login" name="">

在3.1下会生成以下HTML:

under 3.1 would generate the following HTML:

<form id="customerLoginForm" action="/login" method="post">

现在生成:

<form id="customerLoginForm" action="/webapp/login" method="post">

其中"webapp"是我们webapp的Websphere中的上下文路径.

where "webapp" is the context path in Websphere of our webapp.

在上面的示例中,对/login的GET请求成功,但是返回了不正确的表单action ="/webapp/login"(表单将POST提交回相同的URL).因此,提交表单后,我会收到404错误的网址错误.

In the example above, the GET request to /login is successful but returns the improper form action="/webapp/login" (the form submits a POST back to the same URL). So when the form is submitted I get a 404 bad URL error.

3.2中有什么变化吗?是否有地方要告诉Spring忽略上下文路径?我可以返回将所有绝对路径更改为相对路径(例如,登录"而不是"/登录"),但我不希望这样做,因为我的Web应用程序中有20多种表单.

Did something change in 3.2? Is there somewhere to tell Spring to ignore the context path? I could go back change all absolute paths to relative paths (e.g., "login" instead of "/login") but I'd prefer not to since there are 20+ forms in my webapp.

推荐答案

对不起,它不是bug,而是一项新功能.请查看此jira:如果表单标签不存在,则表单标签应位于contextPath和servletPath之前

Sorry it's not a bug, it's a new feature. Please see this jira: Form tag should prepend the contextPath and servletPath if not present

显然是在3.2.3上回滚的.因此,您可能会发现仅升级到最新版本即可使代码行为恢复正常

Which apparently got rolled back on 3.2.3. So you might see your code behavior return to normal just by upgrading to latest version

这篇关于Spring MVC附加上下文路径以形成动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆