1

Ich benutze Spring mvc web, um ein Formular zu senden. Das Formular wird zwar gut dargestellt, aber wenn ich dieses Formular abschicke, erhalte ich den http Statuscode 400, aber wenn ich die 'edit and send' Funktion von Firefox verwende, trifft es die entsprechende Controller Methode (was nicht passiert wenn ich dieses Formular abschicke von html). Aber wieder gibt es ein anderes Problem, innerhalb dieser Controller-Methode, wenn ich mein ModelAttribute-Objekt überprüfe, finde ich alles in diesem Objekt als null. Was nicht der Fall ist, da ich Werte innerhalb dieses Formulars übergebe.Formular nicht verbuchen Werte, 'Browser bearbeiten und erneut senden' funktioniert

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
    <%@ include file="include.jsp"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
    <title>${message}</title> 
    </head> 
    <body> 
     General: 
<br> 
<form:form modelAttribute="initialMatchConfiguration" action="../match/configure" method="post" > 
    Date and time: 
    <form:input path="dateAndTimeOfMatch" type="text" /> 
    <br> Match Type: 
    <form:select path="matchType"> 
     <option value="friendly">friendly</option> 
     <option value="international">international</option> 
     <option value="domestic">domestic</option> 
     <option value="local">local tournament</option> 
    </form:select> 
    <br> Match Rules Configuration: 
    <form:select path="matchConfigurationId"> 
     <option value="0">Random</option> 
     <option value="1">T20</option> 
     <option value="2">One Day</option> 
     <option value="3">Test</option> 
    </form:select> 
    <button type="button">Create a new rule configuration</button> 
    <br> Tournament: 
    <form:input type="text" path="tournament" /> 
    <form:hidden path="tournamentId"/> 
    <button type="button">Create a new Tournament</button> 
    <br> Played at Stadium: 
    <form:input type="text" path="stadium" /> 
    <form:hidden path="stadiumId"/> 
    <button type="button">Create a new stadium</button> 
    <br> <input type="submit" value="Save" /> 
</form:form> 
    </body> 
    </html> 

Nach Methode Form zu machen:

@RequestMapping(value = "/match/configure", method = RequestMethod.POST) 
public String configureMatch(@ModelAttribute("initialMatchConfiguration") InitialMatchConfiguration initialMatchConfig, Model model){ 
    System.out.println(initialMatchConfig); 
    return "config-match-team"; 
} 

InitialMatchConfiguration Klasse

public class InitialMatchConfiguration { 
private Date dateAndTimeOfMatch; 
private String matchType; 
private Long matchConfigurationId; 
private Long tournamentId; 
private Long stadiumId; 
private String tournament; 
private String stadium; 
public Date getDateAndTimeOfMatch() { 
    return dateAndTimeOfMatch; 
} 
public void setDateAndTimeOfMatch(Date dateAndTimeOfMatch) { 
    this.dateAndTimeOfMatch = dateAndTimeOfMatch; 
} 
public String getMatchType() { 
    return matchType; 
} 
public void setMatchType(String matchType) { 
    this.matchType = matchType; 
} 
public Long getMatchConfigurationId() { 
    return matchConfigurationId; 
} 
public void setMatchConfigurationId(Long matchConfigurationId) { 
    this.matchConfigurationId = matchConfigurationId; 
} 
public Long getTournamentId() { 
    return tournamentId; 
} 
public void setTournamentId(Long tournamentId) { 
    this.tournamentId = tournamentId; 
} 
public Long getStadiumId() { 
    return stadiumId; 
} 
public void setStadiumId(Long stadiumId) { 
    this.stadiumId = stadiumId; 
} 
public String getTournament() { 
    return tournament; 
} 
public void setTournament(String tournament) { 
    this.tournament = tournament; 
} 
public String getStadium() { 
    return stadium; 
} 
public void setStadium(String stadium) { 
    this.stadium = stadium; 
} 

} 

anfordern, wenn Firefo gefeuert:

@RequestMapping(value = "/match/create", method = RequestMethod.GET) 
public String createMatch(Model model){ 
    model.addAttribute("initialMatchConfiguration", new InitialMatchConfiguration()); 
    return "config-match-initial"; 
} 

Nach Methode das Formular abzuschicken ist x bearbeiten und erneut senden Werkzeug:

Request-Header:

POST http://localhost:8090/scoreboard.web/score/match/configure 

Host: localhost:8090 
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/51.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
Referer: http://localhost:8090/scoreboard.web/score/match/create 
Connection: keep-alive 
Upgrade-Insecure-Requests: 1 
Cache-Control: max-age=0 

Anfrage Körper:

Content-Type: application/x-www-form-urlencoded 
Content-Length: 107 

dateAndTimeOfMatch=&matchType=friendly&matchConfigurationId=0&tournament=&tournamentId=&stadium=&stadiumId= 
+0

teilen Sie die Anfrage Körper gesendet als Teil der Anfrage weiter zu kommentieren – Barath

+0

Aktualisiert die Frage mit Anfrage/Antwort. –

+0

überprüfen Sie diese eine -> es ist Datum ändern Sie den Typ zu type = "date" – Barath

Antwort

1

URSACHE: Änderung

die Art der dateAndTimeOfMatch von Text auf dem neuesten Stand

und in Form-Klasse:

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 
    private Date dateAndTimeOfMatch; 

Form:

<form:form modelAttribute="initialMatchConfiguration" action="../match/configure" method="post" > 
Date and time: 
<form:input path="dateAndTimeOfMatch" type="date" /> 
<br> Match Type: 
<form:select path="matchType"> 
    <option value="friendly">friendly</option> 
    <option value="international">international</option> 
    <option value="domestic">domestic</option> 
    <option value="local">local tournament</option> 
</form:select> 
<br> Match Rules Configuration: 
<form:select path="matchConfigurationId"> 
    <option value="0">Random</option> 
    <option value="1">T20</option> 
    <option value="2">One Day</option> 
    <option value="3">Test</option> 
</form:select> 
<button type="button">Create a new rule configuration</button> 
<br> Tournament: 
<form:input type="text" path="tournament" /> 
<form:hidden path="tournamentId"/> 
<button type="button">Create a new Tournament</button> 
<br> Played at Stadium: 
<form:input type="text" path="stadium" /> 
<form:hidden path="stadiumId"/> 
<button type="button">Create a new stadium</button> 
<br> <input type="submit" value="Save" /> 

InitialMatchConfiguration.java:

public class InitialMatchConfiguration { 

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 
private Date dateAndTimeOfMatch; 
private String matchType; 
private Long matchConfigurationId; 
private Long tournamentId; 
private Long stadiumId; 
private String tournament; 
private String stadium; 

//getters and setters 

} 

Controller:

@RequestMapping(value = "/match/configure", method = RequestMethod.POST) 
    public String configureMatch(@ModelAttribute("initialMatchConfiguration") InitialMatchConfiguration initialMatchConfig, Model model){ 
     System.out.println(initialMatchConfig.toString()); 

     return "config-match-team"; 
    } 

Antwort:

** InitialMatchConfiguration [dateAndTimeOfMatch = Di 10. Januar 05.30.00 IST 2017 = Matchtype international, matchConfigurationId = 2, tournamentId = null, stadiumId = null, Turnier = sa, Stadion =] **

+0

Haben Sie einen Unterschied in Ihrem Code und meinem Code festgestellt? –

+0

Bitte geben Sie Ihren Code nicht kommentieren können. teilen Sie die InitialMatchConfiguration.java und Formular sowie – Barath

+0

Erforderliche Dinge in Frage gestellt. –

Verwandte Themen