springMVC请求发生重复路径

http://localhost:8080/springmvcTest/html/BookAddForm.jsp

jsp页面
<div class="container">
    <h1>SpringMVC 添加书籍</h1>
    <hr>
    <form:form commandName="book" action="book_save" method="post" >
            <div class="form-group">
                <label for="category">Category:</label>
              <select class="form-control" id="category" NAME="category" >
                  <option>文学</option>
                  <option >计算机编程</option>
                  <option>健康</option>
                  <option>旅行</option>
                  <option>科普</option>
                  <option>天文学</option>
                  <option>医学</option>
                  <option>人文杂志</option>
              </select>
            </div>
            <div class="form-group">
                <label for="title">Title:</label>
                <input class="form-control" id="title" name="title" placeholder="Enter Title:">
            </div>
            <div class="form-group">
                <label for="author">Author</label>
                <input class="form-control" id="author" name="author" placeholder="Enter Author:">
            </div>
            <div class="form-group">
                <label for="isbn">ISBN</label>
                <input class="form-control" id="isbn" name="isbn" placeholder="Enter ISBN:">
            </div>
            <div class="form-group">

                <input id="reset" type="reset" tabindex="4" value="reset" class="btn btn-sm btn-success">
                <input id="submit" type="submit" tabindex="5" value="add Book" class="btn btn-sm btn-success">
            </div>
    </form:form>
</div>
Controller 代码
@RequestMapping(value = "/book_save" ,method = RequestMethod.POST)
    public String saveBook(@ModelAttribute Book book) {
        bookService.save(book);
        System.out.println(book.getCategory());
        return "redirect:/book_list";
    }

请求出现如下URL地址:http://localhost:8080/springmvcTest/html/book_save

解决方案:jsp提交是时地址改为:

action="${pageContext.request.contextPath}/book_save"

转载于:https://my.oschina.net/lcyanxi/blog/782398

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值