2012-03-22 17 views
8

Ho trovato un sacco di domande "How to open form result in new window", ma sto affrontando un problema opposto.Perché il modulo di invio apre una nuova finestra/scheda?

ho forma:

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

allora ho controller con metodo di gestione

@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"; 
} 

Tutto funziona bene, tranne il fatto che risultato si apre in una nuova finestra/tab.

soluzione che ho trovato e sta lavorando è quello di aggiungere attributo target:

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

Ma _self è di default per quanto ne so.

Mi chiedo perché sta succedendo.

ho controllato generato HTML e mi sembra ok:

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

modificare intestazioni aggiunto

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 metodo aggiunto per result.form

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

Il mio cont classe rullo inizia con:

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

Hai lo stesso comportamento quando sei sia Javascript? – sinuhepop

+0

Il comportamento è lo stesso con JS disabilitato. – Betlista

+1

Che ne pensi di diversi browser? Gli altri siti Web e link funzionano bene? – adarshr

risposta

6

problema era in base tag. Avevo intenzionalmente target="_blank" nel tag, probabilmente perché ho copiato l'esempio da w3schools: -/

+0

Per quelli di voi che non hanno 'target =" _ blank "' nel tag '

', questa è sicuramente la soluzione. –

Problemi correlati