JSP 404找不到错误显示当我运行为java应用程序[重复]

inn6fuwd  于 2022-12-07  发布在  Java
关注(0)|答案(1)|浏览(135)
    • 此问题在此处已有答案**:

Spring Boot does not honor @WebServlet(3个答案)
10个月前关闭。


这是我的servlet类

package login.example;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet(name = "LogoutServlet", urlPatterns = {"/LogoutServlet"})
public class LogoutServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public LogoutServlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        PrintWriter out = response.getWriter();
        response.setContentType("text/html");
        HttpSession session = request.getSession();
        session.invalidate();

        out.println("Thank you,you are successfully logged out");
        out.close();
    }

下面是web.xml

<dependency>
    <groupId>org.apache.tomcat</groupId>
    <artifactId>servlet-api</artifactId>
    <version>6.0.39</version>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.1</version>
            </dependency>

}
在springboot项目中,我必须作为java应用程序运行,但它会给出404错误,而当我作为服务器上的运行时,它完全工作。我应该怎么做?

xfb7svmp

xfb7svmp1#

我认为您将项目构建为WAR,在这种情况下,正确的方法是在servlet容器(如Tomcat)中启动应用程序,而不是作为java应用程序运行。

相关问题