Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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
Hibernate Spring Mvc控制器-删除问题_Hibernate_Spring Mvc_Controller_Dao - Fatal编程技术网

Hibernate Spring Mvc控制器-删除问题

Hibernate Spring Mvc控制器-删除问题,hibernate,spring-mvc,controller,dao,Hibernate,Spring Mvc,Controller,Dao,我在一个j2ee项目中工作(pojo层、Dao层(hibernate)、服务层(spring)、视图(SpringMVC)) 我在每一行后面都有一个文章表,我想添加一个链接来删除它 这是我的看法 <c:if test="${!empty articles}"> <table> <tr> <th>Article ID</th> <th>Article Name</th>

我在一个j2ee项目中工作(pojo层、Dao层(hibernate)、服务层(spring)、视图(SpringMVC)) 我在每一行后面都有一个文章表,我想添加一个链接来删除它

这是我的看法

<c:if test="${!empty articles}">
<table>
    <tr>
        <th>Article ID</th>
        <th>Article Name</th>
        <th>Article Desc</th>
        <th>Added Date</th>
        <th>operation</th>
    </tr>

    <c:forEach items="${articles}" var="article">
        <tr>
            <td><c:out value="${article.articleId}"/></td>
            <td><c:out value="${article.articleName}"/></td>
            <td><c:out value="${article.articleDesc}"/></td>
            <td><c:out value="${article.addedDate}"/></td>
            <td><a href="articles/${article.articleId}">delete</a></td>
        </tr>
    </c:forEach>
</table>
这是服务层

    @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void removeArticle(Integer id) {
    articleDao.removeArticle(id);
}
这是Dao层(我尝试查找文章,然后将其删除)

但是,当我运行项目并单击删除链接时,出现了404错误 Etat HTTP 404-/Spring3Hibernate/articles/1 说明请求的资源(/Spring3Hibernate/articles/1)不可用


有人能帮我吗?

尝试删除请求方法。对于将更改服务器/db中的值的内容,不建议使用GET方法。如果您想坚持使用post,请将其设置为表单提交,而不是href

RequestMapping(value="/articles/{articleId}", method=RequestMethod.DELETE)

此外,这看起来是一个非常大的安全问题。我可以编写非常简单的10行程序,使用get或post请求从/articles/1调用/articles/{anynumber}并删除您的全部数据。我建议在设计此类应用程序时只考虑它

你确定“a href”部分发送的是帖子而不是GET请求吗?但是他的链接仍然会以GET的形式发送请求。这比使用RequestMethod.POST更好吗?我忘了提到这一点,谢谢你的纠正。它必须是来自form.HTTP Status 405的帖子-请求方法“post”不受支持。我尝试了所有这些方法,但仍然发生了上述情况。删除请求已转换为POSTCan您提供了一些关于防止此安全漏洞的提示吗?
    public void removeArticle(Integer id) {
            //to get the article
    Article article = (Article) sessionFactory.getCurrentSession().load(
            Article.class, id);
    if (null != article) {
        sessionFactory.getCurrentSession().delete(article);
    }

}
RequestMapping(value="/articles/{articleId}", method=RequestMethod.DELETE)
 <td><a href="articles/${article.articleId}">delete</a></td>
@RequestMapping(value="/articles/{articleId}", method=RequestMethod.POST)