如何通过IntelliJ IDEA访问index.jsp作为欢迎文件

stszievb  于 5个月前  发布在  IntelliJ IDEA
关注(0)|答案(1)|浏览(46)

我试图做一个简单的管理应用程序,我们管理教师和他们教的课程,我使用Java servlet和JSP。但问题是,当我使用Tomcat运行时,控制台中没有错误,但当我试图通过localhost访问页面时,我得到了一个“404”消息错误,当我们使用Tomcat服务器运行应用程序时,我如何访问页面
下面是代码的代码结构,便于更好的理解


的数据


index.jsp编码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Main Page</title>
</head>
<body>
<h1>Welcome to the Main Page</h1>

<ul>
    <li><a href="${pageContext.request.contextPath}/courses.jsp">Courses</a></li>
    <li><a href="${pageContext.request.contextPath}/teachers.jsp">Teachers</a></li>
</ul>
</body>
</html>

字符串
当我去这个网址http://localhost:8089/TeacherAndCousrseMangemntWepApp/的主页应该出现吗?

eeq64g8w

eeq64g8w1#

index.jsp在Tomcat服务器配置web.xml中定义为welcome-file
如果您使用的是Tomcat示例,并且没有指定welcome-file-list,则容器(Tomcat)将查看其 default,即Tomcat示例中的/conf/web.xml
这些是线:

<welcome-file-list> 
  <welcome-file>index.html</welcome-file> 
  <welcome-file>index.htm</welcome-file>     
  <welcome-file>index.jsp</welcome-file> 
</welcome-file-list>

字符串
你还可以在这里找到其他有用的信息。例如*.jsp资源是如何Map的。
您的问题可能与此问题标题中描述的相同:Failed to load resource files when mapping Servlet on URL pattern of /。但如果没有详细信息,很难预测确切的原因。如果您有一个servletMap到/,则它会覆盖默认的servletMap。
url模式/ is被默认的servlet使用,它能够加载没有被其他servletMap的静态资源。当你切换到这个模式时,它就停止工作了。所以,你应该保留一个servletMap。

<servlet-mapping>
   <servlet-name>Servlet</servlet-name>
   <url-pattern>/Servlet</url-pattern>
</servlet-mapping>

相关问题