老师,我的在eclipse下一直报404错误

老师,我的在eclipse下一直报404错误

HTTP Status 404 – Not Found

Type Status Report

Message /index

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.37


代码:

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Insert title here</title>

</head>

<body>

<%

response.sendRedirect("/index");

%>

</body>

</html>



package com.damu.servlet;


import java.io.IOException;

import java.util.List;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import com.damu.dao.UserDao;

import com.damu.entity.Users;


@WebServlet("/index")

public class UersFindServlet extends HttpServlet{

//当访问index时,会映射到servlet,然后调用这里的方法,然后跳转到index页面

private UserDao userDao=new UserDao();

@Override

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

// TODO Auto-generated method stub

this.doPost(req, resp);

}


@Override

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

// TODO Auto-generated method stub

//得到User的查询结果list

List<Users> list=userDao.findAll();

//将list作为一个属性值方便获取

req.setAttribute("UsersList", list);

//然后将list发送到页面

req.getRequestDispatcher("index.jsp").forward(req, resp);

}

}

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>

<head>

    <title>慕课网用户管理中心</title>

    <link rel="stylesheet" href="lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">

    <script src="lib/2.2.4/jquery-1.12.4.min.js"></script>

    <script src="lib/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>

</head>

<body>

<div class="container">

    <div class="row">

        <div class="page-header">

            <h1>慕课网后台管理系统 <small>用户数据管理中心</small></h1>

        </div>

    </div>

    <div class="row">

        <div class="jumbotron">

            <h1>MyBatis基础入门课程!</h1>

            <p>通过一个项目来完成基础部分的学习</p>

            <p><a class="btn btn-primary btn-lg" href="#">查看更多,请上慕课网</a></p>

            <p><a class="btn btn-primary btn-lg" href="">新增用户</a></p>

        </div>

    </div>

    <div class="row">

        <table class="table table-hover table-striped">

            <tr>

                <th>用户编号</th>

                <th>登录账号</th>

                <th>用户昵称</th>

                <th>邮箱</th>

                <th>联系方式</th>

                <th>账号创建时间</th>

                <th>用户状态</th>

                <th>操作</th>

            <c:forEach items="${UsersList}" var="user">

            <tr>

            <td>${user.id}</td>

            <td>${user.username}</td>

            <td>${user.nickname}</td>

            <td>${user.email}</td>

            <td>${user.phone}</td>

            <td>${user.createTime}</td>

            <c:if test="${user.userStatus == 0}">

            <td>正常</td>

            </c:if>

            <c:if test="${user.userStatus == 1}">

            <td>锁定</td>

            </c:if>

            <c:if test="${user.userStatus == 2}">

            <td>删除</td>

            </c:if>

            <td>

            <a>查看</a>

            <a>修改</a>

            <a>删除</a>

            </td>

            </tr>

            </c:forEach>

            </tr>

        </table>

    </div>

</div>

</body>

</html>

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns="http://xmlns.jcp.org/xml/ns/javaee"

         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

         id="WebApp_ID" version="3.1">

    <display-name>mb</display-name>


    <welcome-file-list>

        <welcome-file>index.html</welcome-file>

        <welcome-file>index.htm</welcome-file>

        <welcome-file>home.jsp</welcome-file>

        <welcome-file>default.html</welcome-file>

        <welcome-file>default.htm</welcome-file>

        <welcome-file>default.jsp</welcome-file>

    </welcome-file-list>


</web-app>


spacer.gif

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
提问者 唏哩哗啦v 2019-03-18 17:24:15

是在webapp下的,home.jsp和index.jsp都在webapp下,不是Webinf下

  • 问一下同学使用的是IDEA还是eclipse,在地址栏中的访问路径是什么?建议同学反馈一下。祝:学习愉快~
    2019-03-18 18:47:37
好帮手慕阿满 2019-03-18 17:15:41

同学你好,404问题是访问资源不存在,路径问题。问一下同学index.jsp是在WEB-INF目录下吗?建议将index.jsp移动到webapp目录下,而不是WEB-INF目录下。

如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
Java数据库开发与实战应用2018版
  • 参与学习           人
  • 提交作业       277    份
  • 解答问题       4297    个

Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师