HTTP状态404请求的资源不可用

时间:2016-12-08 13:50:34

标签: java spring jsp annotations

这是我的productdetails.jsp的代码。我已经将页眉和页脚作为单独的jsp文件包含在内。当我尝试加载页面时,图像没有显示。该项目是一个maven项目。其他页面在项目正常运作

header.jsp中

<title>Products|Phonaholic</title>






<!DOCTYPE html>

<html>
<head>
<title>Phonaholic</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
</head>

<body>

<nav class="navbar navbar-default navbar-fixed-top" style="background-color:white;">

  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-expanded="false" style="margin-top:20px;">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar" style="color:#1E7145"></span>
        <span class="icon-bar" style="color:#1E7145"></span>
        <span class="icon-bar" style="color:#1E7145"></span>
       </button>
       <a class="navbar-brand" href='/phonaholic/'><img class="img-responsive"     style="max-width:175px;margin-top:-3px;" src="images\Logomakr_2A1smS.png" /></a>
     < /div>


    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="myNavbar">
    <ul class="nav navbar-nav">
    <li><a href='/phonaholic/' id="navig">Home</a></li>

       <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false" id="navig">Products<span class="caret" style="color: #1E7145"></span></a>
          <ul class="dropdown-menu">
            <li><a href='/phonaholic/basic/'>Basic Phone</a></li>
            <li><a href='/phonaholic/smart/'>Smart Phone</a></li>
            <li><a href='/phonaholic/tab'>Tablets</a></li>            
          </ul>
        </li>

       <li><a href='/phonaholic/about/' id="navig">About</a></li>
    <li><a href='/phonaholic/contact/' id="navig">Contact Us</a></li>
 </ul>


  <ul class="nav navbar-nav navbar-right">
    <li><a href='/phonaholic/register/' id="navig"><i class="fa fa-user" >Register</i></a></li>      
    <li><a href='/phonaholic/login/' id="navig"><i class="fa fa-sign-in" >Login</i></a></li>
  </ul>


</div><!-- /.navbar-collapse -->

 </div><!-- /.container-fluid -->

</nav>

</body>

</html>

产品详情.jsp        

var prod=       {"id":41,"name":"gjavsd","brand":"hasbsh","category":"bsha","desc":"ahbas","price":100.0};
angular.module("productApp",[])

.controller("productController",function($scope){

    $scope.prodData=prod;

    $scope.sort=function(keyname){
    $scope.sortKey=keyname;
    $scope.reverse=!$scope.reverse;
    }

});
</script>

   <div class="container-fluid" ng-app="productApp" ng-    controller="productController"><br><br><br><br><br>
<input type="text" ng-model="search">
<table class="table table-hover">
  <thead>
    <tr><th></th><th ng-click="sort('id')">Product ID</th><th ng-click="sort('name')">Product Name</th><th ng-click="sort('brand')">band</th><th ng-click="sort('category')">Category</th><th ng-click="sort('price')">Price</th>    </tr>
  </thead>

  <tbody>
     <tr ng-repeat="product in prodData | filter:search | orderBy:sortKey:reverse"><td><img src="images\{{product.id}}.jpg" style="max-width: 175px;max-height: 100px; "/></td><td>{{product.id}}</td><td>{{product.name}}</td><td>{{product.brand}}</td><td>{{product.category}}</td><td>{{product.price}}</td><td><button type="submit" class="button" onclick="productdetails/{{product.id}}">View</button></td></tr>
  </tbody>
</table>




</div>

controller.java

@RequestMapping("/productdetails/{id}")
public ModelAndView ProductDetails(@PathVariable("id") int id)
{
    Product products=productDAO.getProductById(id);
    String productList=new Gson().toJson(products);
    ModelAndView model=new ModelAndView("product");
    model.addObject("productList",productList);
    return model;

}

单击视图页面源时图像的路径

http://localhost:9080/phonaholic/productdetails/images/Logomakr_2A1smS.png

由于图片位于网址

,因此无法显示图片

http://localhost:9080/phonaholic/images/Logomakr_2A1smS.png

如何更改正确显示图像的网址。

编辑: 我找到了一个我添加的解决方案

img标签中的

\ phonaholic \ images \ Logomakr_2A1smS.png。

但任何人都可以告诉我发生在这个页面上的其他页面正常运行而没有在图片网址之前添加上述\ phonaholic \。

1 个答案:

答案 0 :(得分:0)

我认为这只是src中的路径问题。你的header.jsp在哪里?我的意思是它在productdetails文件夹中吗?