HTTP状态 404 - 未找到

访问网址http://localhost:8080/brand-demo/selectAllServlet

出现如下情况

HTTP状态 404 - 未找到_第1张图片

HTTP状态 404 - 未找到_第2张图片

JDK版本:JDK17

Tomcat版本:Tomcat 9.0.70

Intellij IDEA版本:2021.2.1

错误原因:访问网址http://localhost:8080/brand-demo/selectAllServlet

正确网址:http://localhost:8080/brand_demo_war_exploded/selectAllServlet

总结:

Module名为brand-demo,但是Tomcat Server Development Artifact 是brand_demo_war_exploded

因此,修改index.html为




    
    Title



查询所有


对应的SelectAllServlet.java为

package com.itheima.web;

import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;

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 java.io.IOException;
import java.util.List;

@WebServlet("/selectAllServlet")
public class SelectAllServlet extends HttpServlet {
    private BrandService service = new BrandService();

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

        //1.调用BrandService完成查询
        List brands = service.selectAll();


        //2.存入request域中
        req.setAttribute("brands",brands);

        //3.转发到brand.jsp
        req.getRequestDispatcher("/brand.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
HTTP状态 404 - 未找到_第3张图片

你可能感兴趣的:(java,tomcat)