Zunächst einmal entschuldige mich, diese wiederholte Frage zu stellen.
In meiner Frühlingsanwendung habe ich user.jsp
und professional.jsp
hier ist mein User.jsp:
<form:form action="profile/user" modelAttribute="profile">
<div>
<jsp:include page="professional.jsp"></jsp:include>
</div>
</form:form>
Und hier ist meine professional.jsp:
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://Java.Sun.com/jsp/jstl/core"%>
<fieldset id="profile_proffiesional">
<form:form action="profile/proffiesional" modelAttribute="PROFESSIONAL" method="POST">
<p>
<label for="position">Position</label>
<form:input path="position" tabindex="4" />
</p>
<p>
<label for="location">Location</label>
<form:input path="location" tabindex="5" />
</p>
<p>
<label for="description">Description</label>
<form:input path="description" tabindex="5" />
</p>
<p>
<input type="submit" value="Add">
</p>
</form:form>
</fieldset>
Und hier ist meine Controller-Klasse:
@Controller
@RequestMapping(value = "profile")
public class UserProfileController {
@Autowired
private UserService userService;
@Autowired
private SessionData sessionData;
@RequestMapping(value = "user", method = RequestMethod.GET)
public String user(Model model) throws Exception {
model.addAttribute("PROFESSIONAL", new UserProfessionalForm());
model.addAttribute("EDUCATIONAL", new UserEducationalForm());
model.addAttribute("AWARDS", new UserAwardsForm());
return "profile/user";
}
@RequestMapping(value = "proffessional", method = RequestMethod.POST)
public @ResponseBody
String forgotPassword(UserProfessionalForm professionalForm,
BindingResult result, Model model) {
UserProfileVO userProfileVO = new UserProfileVO();
userProfileVO.setUser(sessionData.getUser());
userService.saveUserProfile(userProfileVO);
model.addAttribute("professional", professionalForm);
return "Your Professional Details Updated";
}
}
Problem
ist, wenn wir in professional.jsp
auf die Schaltfläche Add
klicken. In der Serverkonsole wird keine Antwort angezeigt. Die folgende Warnmeldung wird angezeigt:
29 Mar, 2013 1:03:51 PM org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver handleHttpRequestMethodNotSupported
WARNING: Request method 'POST' not supported
Warum kommt diese Warnung? Ich habe bereits method = "POST" angegeben ..
Bitte helfen Sie ..
Ihre user.jsp:
<form:form action="profile/proffesional" modelAttribute="PROFESSIONAL">
---
---
</form:form>
In Ihrer Controller-Klasse:
(machen Sie es als Bedeutung der vollständige Methodenname. Ich denke, Sie sind Datensatz in DB einfügen.)
@RequestMapping(value = "proffessional", method = RequestMethod.POST)
public @ResponseBody
String proffessionalDetails(
@ModelAttribute UserProfessionalForm professionalForm,
BindingResult result, Model model) {
UserProfileVO userProfileVO = new UserProfileVO();
userProfileVO.setUser(sessionData.getUser());
userService.saveUserProfile(userProfileVO);
model.addAttribute("PROFESSIONAL", professionalForm);
return "Your Professional Details Updated";
}
Ich hatte csrf in meiner Sprint-Sicherheits-XML-Datei aktiviert, also habe ich nur eine Zeile im Formular hinzugefügt:
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
Auf diese Weise konnte ich das Formular mit dem Attribut model
absenden.
In Jsp:
action="profile/proffiesional"
Im Controller
@RequestMapping(value = "proffessional", method = RequestMethod.POST)
Rechtschreibfehler
Sie verpassen die @ModelAttribute
-Annotation für den UserProfessionalForm professionalForm
-Parameter in der forgotPassword
-Methode.
@RequestMapping(value = "proffessional", method = RequestMethod.POST)
public @ResponseBody
String forgotPassword(@ModelAttribute UserProfessionalForm professionalForm,
BindingResult result, Model model) {
UserProfileVO userProfileVO = new UserProfileVO();
userProfileVO.setUser(sessionData.getUser());
userService.saveUserProfile(userProfileVO);
model.addAttribute("professional", professionalForm);
return "Your Professional Details Updated";
}
Versuche dies
@RequestMapping(value = "proffessional", method = RequestMethod.POST)
public @ResponseBody
String forgotPassword(@ModelAttribute("PROFESSIONAL") UserProfessionalForm professionalForm,
BindingResult result, Model model) {
UserProfileVO userProfileVO = new UserProfileVO();
userProfileVO.setUser(sessionData.getUser());
userService.saveUserProfile(userProfileVO);
model.addAttribute("professional", professionalForm);
return "Your Professional Details Updated";
}
Zur Information entfernte ich das Aktionsattribut und bekam diese Fehlermeldung, wenn ich einen Ajax-Poste anrufe. Auch wenn mein Aktionsattribut im Formular so aussieht action="javascript://;"
Ich dachte, ich hätte es vom Ajax-Aufruf und der Serialisierung des Formulars erhalten, aber ich habe das Dummy-Aktionsattribut wieder zum Formular hinzugefügt, und es funktionierte.