Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring进程POST数据-注释右侧控制器_Java_Forms_Spring_Request - Fatal编程技术网

Java spring进程POST数据-注释右侧控制器

Java spring进程POST数据-注释右侧控制器,java,forms,spring,request,Java,Forms,Spring,Request,我在配置SpringMVC以在正确的控制器中处理表单POST数据时遇到问题。我有一个add操作,它将向数据库中添加一条新记录 提交表单后,我收到404错误(http://localhost:8084/lyricsBase/song/submit.html),所以我想我在发送表单提交时犯了一些错误 这是我的控制器代码: public class SongController extends MultiActionController { [...] @RequestMapping

我在配置SpringMVC以在正确的控制器中处理表单POST数据时遇到问题。我有一个
add
操作,它将向数据库中添加一条新记录

提交表单后,我收到404错误(
http://localhost:8084/lyricsBase/song/submit.html
),所以我想我在发送表单提交时犯了一些错误

这是我的控制器代码:

public class SongController extends MultiActionController {

    [...]
    @RequestMapping(value = "/song/submit.html", method = RequestMethod.POST)
    public ModelAndView submit(@RequestParam("song") Song song) throws Exception {
        HashMap model = new HashMap();
        model.put("song", song);
        // or do something better here...
        return new ModelAndView("t.edit", model);
    }
这是视图表单标记:

<form:form method="POST" commandName="song" action="submit.html">

我的申请代码可以在上找到。以下是重要的文件:、和(该类是一个多控制器,因为我不想为每个操作创建单独的文件)

我不知道这是否重要,但我在视图层中使用了平铺(其中使用了逻辑视图名称)


此外,我不完全理解spring路由是如何工作的。到目前为止,我还在servlet xml中定义映射,但不知道这是否是一种好方法…

尝试一下,如果您的应用程序URL为:

http://localhost:8084/lyricsBase/song/submit.html
请求映射应类似(删除映射中的第一个“/”):

jsp中的表单标记应为:

<form:form method="POST" commandName="song" action="song/submit.html">

这首歌的标价是多少?我不确定Spring是否将发布的数据转录或反序列化到对象/实体中。 你可以试着改变

@RequestMapping(value = "/song/submit.html", method = RequestMethod.POST)
public ModelAndView submit(@RequestParam("song") Song song) throws Exception {
进入

看看有没有人捡到

另一种方法是从请求对象读取参数

@RequestMapping(value = "/song/submit.html", method = RequestMethod.POST)
public ModelAndView submit(HttpServletRequest request) throws Exception {

Object song = request.getParameter("song");

德国劳埃德船级社

请将相关的代码段添加到您的问题中。@KeesdeKooter添加了重要的代码段。如果您使用@RequestMapping注释映射请求,则无需将其映射到servlet.xml中。请在浏览器调试工具中检查提交表单时调用的url。是/song/submit.html吗?
@RequestMapping(value = "/song/submit.html", method = RequestMethod.POST)
public ModelAndView submit(@RequestParam("song") String song) throws Exception {
@RequestMapping(value = "/song/submit.html", method = RequestMethod.POST)
public ModelAndView submit(HttpServletRequest request) throws Exception {

Object song = request.getParameter("song");