前提・実現したいこと
index.jspからnavのservicesをクリックした後にRestaurantServletが動く
発生している問題・エラーメッセージ
404 NotFound
該当のソースコード
index
150行目のaタグが上手く行かない、その他Login等は上手くいく 2それ以降のコードは削除しています 3<%@ page language="java" contentType="text/html; charset=UTF-8" 4 pageEncoding="UTF-8"%> 5<!DOCTYPE html> 6<html lang="ja"> 7<head> 8<meta charset="utf-8" /> 9<meta name="viewport" 10 content="width=device-width, initial-scale=1, shrink-to-fit=no" /> 11<meta name="description" content="" /> 12<meta name="author" content="" /> 13<title>GourmentSIBUYA toppage</title> 14<!-- Favicon--> 15<link rel="icon" type="image/x-icon" href="assets/img/favicon.ico" /> 16<!-- Font Awesome icons (free version)--> 17<script src="https://use.fontawesome.com/releases/v5.13.0/js/all.js" 18 crossorigin="anonymous"></script> 19<!-- Google fonts--> 20<link 21 href="https://fonts.googleapis.com/css?family=Merriweather+Sans:400,700" 22 rel="stylesheet" /> 23<link 24 href="https://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic" 25 rel="stylesheet" type="text/css" /> 26<!-- Third party plugin CSS--> 27<link 28 href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" 29 rel="stylesheet" /> 30<!-- Core theme CSS (includes Bootstrap)--> 31<link href="css/styles.css" rel="stylesheet" /> 32<link href="css/search.css" rel="stylesheet" /> 33</head> 34<body id="page-top"> 35 <!-- Navigation--> 36 <nav class="navbar navbar-expand-lg navbar-light fixed-top py-3" 37 id="mainNav"> 38 <div class="container"> 39 <a class="navbar-brand js-scroll-trigger" href="#page-top">GourmentSIBUYA</a> 40 <button class="navbar-toggler navbar-toggler-right" type="button" 41 data-toggle="collapse" data-target="#navbarResponsive" 42 aria-controls="navbarResponsive" aria-expanded="false" 43 aria-label="Toggle navigation"> 44 <span class="navbar-toggler-icon"></span> 45 </button> 46 <div class="collapse navbar-collapse" id="navbarResponsive"> 47 <ul class="navbar-nav ml-auto my-2 my-lg-0"> 48 <li class="nav-item"><a class="nav-link js-scroll-trigger" 49 href="#about">About</a></li> 50 <li class="nav-item"><a class="nav-link js-scroll-trigger" 51 href="./Restaurant">Services</a></li> 52 <li class="nav-item"><a class="nav-link js-scroll-trigger" 53 href="./CreateAccount">新規会員登録</a></li> 54 <li class="nav-item"><a class="nav-link js-scroll-trigger" 55 href="./Login">ログイン</a></li> 56 </ul> 57 </div> 58 </div> 59 </nav> 60</body> 61</html> 62
Restaurant
1package jp.topgate.gourmetshibuya.servlet; 2 3import java.io.IOException; 4 5import javax.servlet.RequestDispatcher; 6import javax.servlet.ServletException; 7import javax.servlet.annotation.WebServlet; 8import javax.servlet.http.HttpServlet; 9import javax.servlet.http.HttpServletRequest; 10import javax.servlet.http.HttpServletResponse; 11 12import jp.topgate.gourmetshibuya.beans.RestaurantBean; 13import jp.topgate.gourmetshibuya.dao.RestaurantDao; 14 15/** 16 * Servlet implementation class RestaurantServlet 17 */ 18@WebServlet("/Restaurant") 19public class RestaurantServlet extends HttpServlet { 20 private static final long serialVersionUID = 1L; 21 22 /** 23 * @see HttpServlet#HttpServlet() 24 */ 25 public RestaurantServlet() { 26 super(); 27 // TODO Auto-generated constructor stub 28 } 29 30 /** 31 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 32 */ 33 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 34 // TODO Auto-generated method stub 35 //response.getWriter().append("Served at: ").append(request.getContextPath()); 36 } 37 38 /** 39 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 40 */ 41 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 42 // TODO Auto-generated method stub 43 //doGet(request, response); 44 RestaurantBean rb = new RestaurantBean(); 45 RestaurantDao rdao = new RestaurantDao(); 46 rb = rdao.getRestaurantDetailInfo(); 47 request.setAttribute("rb", rb); 48 RequestDispatcher rd = request.getRequestDispatcher("Restaurant.jsp"); 49 rd.forward(request, response); 50 } 51 52}
試したこと
doPost,doGetどちらも404
マッピングを変えてもダメでした。
ご教授お願いいたします。
補足情報(FW/ツールのバージョンなど)
Mac
Eclipse
Java11
回答1件
あなたの回答
tips
プレビュー