【发布时间】:2014-09-19 05:05:31
【问题描述】:
简而言之,我有一个 Spring 3.1 MVC 项目,当我点击提交按钮时,我的控制器没有响应 POST 请求。
没有错误,只是没有响应。控制器方法没有被调用。我在显示 INFO 消息的方法中有一个记录器,但没有显示任何内容(其他 INFO 消息确实显示)。 MVC 正在工作(至少是部分工作),因为我从“主页”JSP 页面得到响应,但对 POST 没有任何响应。
我包含了看起来很重要的东西;告诉我你有什么想看的。
控制器类:
@Controller
@RequestMapping(value = "/index")
public class Test {
@Autowired
private IAdminService service;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String lister(Model model) {
model.addAttribute("matieres", service.liserMatiere());
return "Action";
}
@RequestMapping(value="/saveMat", method = RequestMethod.POST)
public ModelAndView saveMat(@ModelAttribute("matiere") Matiere m) {
ModelAndView mav = new ModelAndView();
mav.addObject("mat", m);
service.ajouterMatiere(m);
mav.setViewName("Action");
return mav;
}
这就是 NouvelleMat.jsp:
<%@taglib uri="http://www.springframework.org/tags/form" prefix="f"%>
<f:form class="form-horizontal" method="POST"
action="saveMat" modelAttribute="matiere">
<table>
<tr>
<td>Name:</td>
<td><f:input path="name" maxlength="30" /></td>
</tr>
<tr>
<td>Subject:</td>
<td><f:input path="subject" maxlength="50" /></td>
</tr>
<tr>
<td valign="top">Message:</td>
<td><f:textarea path="note" cols="70" rows="20" /></td>
</tr>
<tr>
<td><f:button type="submit" value="Submit matiere" name="submit" /></td>
<td> </td>
</tr>
</table>
</f:form>
我收到 Etat HTTP 400 客户端发送的请求语法不正确
这是实体实体:
@Entity
public class Matiere implements Serializable{
@SuppressWarnings("unused")
private static final long serialVersionUID = 1L;
@Id
private String name;
private String subject;
private String note;
getters and setters....
}
【问题讨论】:
-
请不要打开与上一个问题相同的新问题。删除这一项或另一项。向我们提供所需的详细信息,以便我们提供帮助。现在,我们需要您为您的日志启用 DEBUG 级别并向我们展示打印的内容。
-
另外,请告诉我们
Matiere。 -
仍然需要那些日志。我们无能为力。
-
我将 @modelattribute 替换为 @requestParam(value="matiere"),Matiere m 并且我得到了这个必需的 Matiere 参数“matiere”不存在
-
请不要做这样不相关的更改。请将您的日志转为 DEBUG 并向我们展示打印的内容。 (对于这种特殊情况,您不会发送
matiere请求参数,默认情况下需要@RequestParam注释参数。)
标签: spring jsp jakarta-ee spring-mvc controller