gpt4 book ai didi

jsp - 为什么我在 tomcat 中部署我的 java web 项目后显示 404

转载 作者:行者123 更新时间:2023-11-28 23:58:29 25 4
gpt4 key购买 nike

<分区>

我在我的服务器上部署了我的项目,它在 index.jsp 上正常工作: index.jsp

但是当我点击以游客身份访问时,它显示404: visitor

我发现可以正常访问jsp文件: home register

但是当页面需要 .java 文件时它显示 404。

这是我在服务器上部署的项目结构: structure class

Servletvisitor.java:

package Controller;

import Model.Blog;
import Model.UserService;
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(name = "ServletVisitor", urlPatterns = "/ServletVisitor")
public class ServletVisitor extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
List<Blog> blogs = UserService.showBlog();

req.setAttribute("blogs", blogs);
req.getRequestDispatcher("visitor.jsp").forward(req, resp);
}

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

index.jsp

<%@ page import="java.util.List" %>
<%@ page import="java.util.Iterator" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>欢迎</title>
</head>
<body>
<div align="center">
<h1>登录</h1>
<%
List<String> info = (List<String>) request.getAttribute("info"); //得到结果
String s;

//若用户有登录操作,则信息不为空
if(info != null) {
Iterator<String> iterator = info.iterator();
while(iterator.hasNext()) {
s = iterator.next();
//若登录成功则跳转到首页
if (s.equals("登录成功")) {
response.sendRedirect("/ServletVIP");
}
//登录不成功提示错误
else {
%>
<%--显示错误--%>
<h4><%=s%></h4>

<%
}
}
}
%>

<form action="/ServletLogin" method="post">
账号:<input type="text" name="account"><br>
<br>
密码:<input type="password" name="password"><br>
<br>
<input type="submit" value="登录">
</form>

<a href="register.jsp">还不是会员?</a><br>
<br>
<a href="/ServletVisitor">以游客身份访问</a>
</div>
</body>
</html>

我的项目结构:

projectstructure

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">

<context-param>
<param-name>JDBC_DRIVER</param-name>
<param-value>com.mysql.cj.jdbc.Driver</param-value>
</context-param>
<context-param>
<param-name>DB_URL</param-name>
<param-value>jdbc:mysql://localhost/account?serverTimezone=GMT%2B8&amp;useSSL=false</param-value>
</context-param>
<context-param>
<param-name>USER</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>PASS</param-name>
<param-value>password</param-value>
</context-param>

<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
<default-content-type>text/html</default-content-type>
</jsp-property-group>
</jsp-config>

该项目在本地主机上运行良好。我认为错误是关于路径的,但我不知道如何解决。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com