嗨我试图找出为什么我的jsp页面中的按钮没有映射到控制器方法。当我点击按钮时,它显示404不可用。
继承人jsp链接 -
<a href="/aucConfirm/${newAuction.idauction}/start" >Start Auction</a>
此控制器方法将拍卖项目添加到“newAuction” -
@RequestMapping(value = "/aucConfirm/{idauction}", method = RequestMethod.GET)
public String confirmAuction(@PathVariable(value = "idauction") int idauction, Model model, HttpServletRequest request) {
AuctionItem addAuction = (AuctionItem) aucRepository.findOne(idauction);
model.addAttribute("newAuction", addAuction);
model.addAttribute("startAction", addAuction.getIdauction() + "/start");
return "aucConfirm";
}
这是链接应映射到的控制器方法 -
@RequestMapping(value = "/aucConfirm/{idauction}/start", method = RequestMethod.GET)
public String startAuction(@PathVariable(value = "idauction") int idauction, RedirectAttributes redirect) {
AuctionItem addAuction = (AuctionItem) aucRepository.findOne(idauction);
List<Image> imageList = (List<Image>) imageRepository.findByidauction(idauction);
addAuction.setMainImage(imageList.get(0).getImagepath());
addAuction.setActive(true);
aucRepository.save(addAuction);
return "listing";
}
链接似乎工作正常,idauction在Web浏览器中填充,它似乎似乎没有映射到控制器。
这是完整的html输出:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/AuctionWebsite/resources/css/dropzone.css" rel="stylesheet">
<title>Confirm</title>
</head>
<body id="product">
<header>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<head>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script type="text/javascript">
$(document).ready(function() {
$('dropdown-toggle').dropdown();
});
</script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data- target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" style="font-size: 40px " href="/AuctionWebsite/">NoBid</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="active"><a href="/AuctionWebsite/">Home</a></li>
<li><a href="/AuctionWebsite/sell">Sell</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Category <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu">
<li><a href="#">Electronics</a></li>
<li><a href="#">Fashion</a></li>
<li><a href="#">Home & Gardens</a></li>
<li><a href="#">Toys & Games</a></li>
<li><a href="#">Sports & Leisure</a></li>
</ul>
</li>
</ul>
<div class="col-sm-6 col-md-6">
<form class="navbar-form navbar-left" >
<div class="form-group">
<input type="text" class="form-control" placeholder="Search for an auction">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
<ul class="nav navbar-nav navbar-right">
<li><a href="/AuctionWebsite/login">Log out</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</header>
<div class="container">
<div class="pb-center-column-inner">
<h1>fffffffffffffffffffffffffffffffffffffffffffffffffffffff</h1>
<hr style="margin-top: 8px;">
<div class="row" style="margin-top: -10px;">
<div class="col-xs-6 col-sm-6 col-md-6"><h4>Auction ID: 55</h4></div>
<div class="col-xs-6 col-sm-6 col-md-6" style="text-align: right;"><h4>Seller: hazardaguess</h4></div>
</div>
<div class="center" style="text-align: left;">
<div id="short_description_block">
<h4>Details:</h4>
<table class="table-data-sheet">
<tr>
<td>Item condition</td>
<td style="padding-left: 12px">New</td>
</tr>
<tr>
<td style="padding-top: 3px">End Time</td>
<td style="padding-left: 12px"></td>
</tr>
<tr>
<td style="padding-top: 3px">Minimum Price</td>
<td style="padding-left: 12px">£0.0</td>
</tr>
<tr>
<td style="padding-top: 3px">Category</td>
<td style="padding-left: 12px">Electronics</td>
</tr>
<tr>
<td style="padding-top: 3px">Returns</td>
<td style="padding-left: 12px">You can return</td>
</tr>
<tr>
<td style="padding-top: 3px">Description</td>
<td style="padding-left: 12px">f</td>
</tr>
</table>
<div class="col-sm-1 col-md-12" style="padding-top: 30px; padding-bottom: 10px">
<form id="my-awesome-dropzone" class="dropzone" action="../aucConfirm/uploadFile/55" method="POST" enctype="multipart/form-data">
<div>
<input type="hidden" name="_csrf" value="944c58d1-33b3-425c-bd20-154b8a138058" />
</div></form>
</div>
<div class="col-sm-6" style="text-align: left;">
<a href="/aucConfirm/55/start" >Start Auction</a>
</div>
<div class="col-sm-6" style="text-align: right;">
<button type="button" class="btn btn-default btn-lg" style="border: 2px solid #FFD700"><a href="/aucConfirm/55/edit">Edit</a></button>
<button type="button" class="btn btn-default btn-lg" style="border: 2px solid #f44336;"><a href="/aucConfirm/55/cancel">Cancel</a></button>
</div>
</div>
</div>
</div>
<script src="/AuctionWebsite/resources/js/dropzone.js"/></script>
<script>
Dropzone.options.myAwesomeDropzone = {
maxFilesize: 4,
parallelUploads: 5,
acceptedFiles: "image/*",
}
</script>
</div>
</body>
</html>
答案 0 :(得分:0)
您已经在/start
控制器方法的confirmAuction
后缀,您需要将其从JSP href
中删除,如下所示:
<a href="/aucConfirm/${newAuction.idauction}" >Start Auction</a>
答案 1 :(得分:0)
它最终非常简单,在路径的开头添加了两个点,现在它正确指向。无论如何,感谢所有的回复。
<a href="../aucConfirm/${newAuction.idauction}/start" >Start Auction</a>