Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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 在执行验证方法后,如何再次接收url参数_Java_Spring - Fatal编程技术网

Java 在执行验证方法后,如何再次接收url参数

Java 在执行验证方法后,如何再次接收url参数,java,spring,Java,Spring,在完成另一个方法后,我想再次获取url参数。我尝试添加行newmodelandview updatealbum.htm?albumId=${album.albumId};但失败了 单击“编辑”链接时的路径是: ?albumId=13 按下提交按钮后的我的路径: ?albumId=13 但当我再次单击“提交”时: AlbumController.java @RequestMapping(value = "*/updatealbum.htm", method = RequestMethod.GET)

在完成另一个方法后,我想再次获取url参数。我尝试添加行newmodelandview updatealbum.htm?albumId=${album.albumId};但失败了

单击“编辑”链接时的路径是:

?albumId=13

按下提交按钮后的我的路径:

?albumId=13

但当我再次单击“提交”时:

AlbumController.java

@RequestMapping(value = "*/updatealbum.htm", method = RequestMethod.GET)
    public ModelAndView updatealbum(
            @RequestParam(value = "albumId") int albumId, ModelMap model,
            @ModelAttribute("album") Album album) {
        Album theAlbum = albumService.findAlbum(albumId);
        List<Category> listCategory = albumService.getListCategory();
        System.out.println(theAlbum.getName());
        model.addAttribute("listCategory", listCategory);
        model.addAttribute("theAlbum", theAlbum);
        return new ModelAndView("updatealbum", "command", new Album());
    }

    @RequestMapping(value = "*/submitupdatealbum.htm", method = RequestMethod.POST)
    public ModelAndView submitUpdateAlbum(
            @Valid @ModelAttribute("album") Album album, BindingResult result,
            @RequestParam(value = "albumId") int albumId,
            ModelMap model) {
        if (result.hasErrors()) {
            System.out.println(result);
            ModelAndView model1 = new ModelAndView("updatealbum");

            model.addAttribute("albumId",albumId);
            System.out.println(albumId);
            return model1;
        }
        Album newAlbum = albumService.findAlbum(albumId);
        album.parseDateToString();
        newAlbum.setReleaseDate(album.getReleaseDate());
        newAlbum.setAuthor(album.getAuthor());
        newAlbum.setDiscount(album.getDiscount());
        newAlbum.setName(album.getName());
        newAlbum.setPicture(album.getPicture());
        newAlbum.setReleaseDate(album.getReleaseDate());
        newAlbum.setSinger(album.getSinger());
        newAlbum.setCategory(album.getCategory());
        albumService.editAlbum(newAlbum);
        model.addAttribute("succsessMgs", "Form successfully submitted");
        return new ModelAndView(setupForm1(model));
    }
updatealbum.jsp

<div class="content">
    <c:if test="${not empty succsessMgs}">
        <div class="mgs">${succsessMgs}</div>
    </c:if>
    <div align="center">
        <form:form action="submitupdatealbum.htm?albumId=${theAlbum.albumId} "
            method='POST' commandName="album">
            <table>
                <tr height="40" align="left">
                    <td>Album Name:</td>
                    <td><form:input path="name" value="${theAlbum.name}"/></td>
                    <td><form:errors path="name" cssStyle="color: #ff0000;"/></td>
                </tr>
                <tr height="40" align="left">
                    <td>Singer:</td>
                    <td><form:input path="author" value="${theAlbum.author}"/></td>
                    <td><form:errors path="author" cssStyle="color: #ff0000;"/></td>
                </tr>

                <tr height="40" align="left">
                    <td>Release Date:</td>
                    <td><form:input path="releaseDate" value="${theAlbum.releaseDate}"/></td>
                    <td><form:errors path="releaseDate" cssStyle="color: #ff0000;"/></td>
                </tr>
                <tr height="40" align="left">
                    <td>Discount:</td>
                    <td><form:input path="discount" value="${theAlbum.discount}"/></td>
                    <td><form:errors path="discount" cssStyle="color: #ff0000;"/></td>
                </tr>
                <tr height="40" align="left">
                    <td>Author:</td>
                    <td><form:input path="author" value="${theAlbum.author}" /></td>
                    <td><form:errors path="author" cssStyle="color: #ff0000;"/></td>
                </tr>
                <%-- <tr height="40" align="left">
                    <td>Picture:</td>
                    <td><form:form enctype="multipart/form-data"
                            modelAttribute="album">
                            <input type="file" name='picture'>
                        </form:form></td>
                </tr> --%>
                <tr height="40" align="left">
                    <td>Image URL:</td>
                    <td><form:input path="picture" value="${theAlbum.picture}" /></td>
                    <td><form:errors path="picture" cssStyle="color: #ff0000;"/></td>

                    </tr>


                <tr height="40" align="left">
                    <td>Category:</td>
                    <td><form:form modelAttribute="album">
                            <form:select path="category.categoryId">
                                <form:option value="" label="Choose category" />
                                <form:options items="${listCategory}" itemValue="categoryId"
                                    itemLabel="categoryName" />
                            </form:select>
                        </form:form></td>
                        <td><springForm:errors path="category.categoryId" cssClass="error" /></td>
                </tr>
                <tr>
                    <td><input name="submit" type="submit" value="Submit" /></td>
                </tr>
            </table>


        </form:form>
    </div>

</div>
使用它

但它不能显示

@RequestMapping(value = "*/submitupdatealbum.htm", method = RequestMethod.POST)
    public ModelAndView submitUpdateAlbum(
            @Valid @ModelAttribute("album") Album album, BindingResult result,
            @RequestParam(value = "albumId") int albumId, ModelMap model) {
        System.out.println("ssssssssssssssssss:" + result);
        if (result.hasErrors()) {
            System.out.println("result:" + result);
            System.out.println("asdasdasd");
            ModelAndView model1 = new ModelAndView(
                    "redirect:updatealbum.htm?albumId=" + album.getAlbumId());
            return model1;
        }