简体   繁体   English

为什么表单提交会打开新窗口/标签?

[英]Why form submit opens new window/tab?

I found a lot of questions "How to open form result in new window" , but I'm facing opposite problem. 我发现了很多问题“如何在新窗口中打开表单结果” ,但我面临着相反的问题。

I have form: 我有形式:

<form:form method="post" commandName="search">
    ...
    <input type="submit" value="Search" />
</form>

Then I have controller with handling method 然后我有控制器与处理方法

@RequestMapping(value = "/search.form", method = RequestMethod.POST)
public String submit( @Valid final SearchObject searchObject, final BindingResult bindingResult ) {
    if ( bindingResult.hasErrors() ) return "forms/search";
    return "redirect:/A/result.form";
}

Everything works fine, except the fact that result is opened in new window/tab. 一切正常,除了在新窗口/选项卡中打开结果的事实。

Solution that I found and is working is to add target attribute: 我找到并正在解决的解决方案是添加目标属性:

<form:form method="post" commandName="search" target="_self">

But _self is default AFAIK. 但是_self是默认的AFAIK。

I'm wondering why is that happening. 我想知道为什么会这样。

I checked generated HTML and it seems to me ok: 我检查生成的HTML,在我看来好吧:

<form id="search" action="/myApp/A/search.form" method="post">

edit added headers 编辑添加的标题

Content-Language    en-US
Content-Length  0
Date    Thu, 22 Mar 2012 16:29:13 GMT
Location    http://localhost:8080/myApp/A/result.form
Server  Apache-Coyote/1.1
Request Headersview source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Cookie  JSESSIONID=E9ACB44C4ED3814814ABE7D96C90135C; GUEST_LANGUAGE_ID=cs_CZ; COOKIE_SUPPORT=true
Host    localhost:8080
Referer http://localhost:8080/myApp/A/search.form
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
Response Headers From Cache
Content-Language    en-US
Content-Length  0
Date    Thu, 22 Mar 2012 16:29:13 GMT
Location    http://localhost:8080/myApp/A/result.form
Server  Apache-Coyote/1.1
Request Headers From Upload Stream
Content-Length  64
Content-Type    application/x-www-form-urlencoded


GET sessions.form

200 OK

localhost:8080

309 B

::1:8080


6ms
HeadersResponseCacheHTML
Content-Language    en-US
Content-Length  309
Content-Type    text/html;charset=utf-8
Date    Thu, 22 Mar 2012 16:29:13 GMT
Server  Apache-Coyote/1.1
Request Headersview source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Cookie  JSESSIONID=E9ACB44C4ED3814814ABE7D96C90135C; GUEST_LANGUAGE_ID=cs_CZ; COOKIE_SUPPORT=true
Host    localhost:8080
Referer http://localhost:8080/myApp/A/search.form
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0

edit 2 added method for result.form 编辑2为result.form添加的方法

@RequestMapping(value = "/result.form", method = RequestMethod.GET)
public String result() {
    return "forms/result";
}

My controller class starts with: 我的控制器类以:

@Controller
@RequestMapping(value = "/A")
public class AController {

Problem was in base tag . 问题出现在基本标签中 I had intentionally target="_blank" in tag, probably because I copied the example from w3schools :-/ 我故意在标签中target="_blank" ,可能是因为我从w3schools复制了这个例子: - /

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Chrome 自定义标签在 chrome 中作为新标签打开而不是在应用程序内,为什么? - Chrome custom tab opens as a new tab in chrome not inside the app why? Chromedriver不会打开链接到新标签页或窗口,而是在当前标签页/窗口中打开了预期的链接 - Chromedriver doesn't opens link a new tab or window , instead the expected link is opened in current tab/window Selenium IE驱动程序将打开新窗口,而不是window.open()上的新选项卡 - Selenium IE Driver opens new window instead of a new tab on window.open() 如何确保 Stage 作为 window 而不是选项卡打开? - How to ensure Stage opens as a window and not a tab? Java新线程打开新窗口? - Java new thread opens new window? Selenium - 单击链接会打开一个新选项卡 - Selenium - Clicking a link opens up a new tab Selenium在SendKeys之后打开新选项卡 - Selenium opens new tab after SendKeys 为什么 Selenium Webdriver 每次运行脚本时都会打开新窗口以及如何修复它? - Why does Selenium Webdriver opens new window for every time run the script and how to fix it? JAVA Swing onclick打开一个新窗口/ JFrame - JAVA Swing onclick opens a new window/JFrame 动作侦听器打开带有结果的新窗口 - Action Listener opens new window with results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM