【问题标题】:Tomcat 6 and 7 dynamic web project eclipseTomcat 6 和 7 动态 web 项目 eclipse
【发布时间】:2015-01-27 20:57:52
【问题描述】:

我正在尝试在 localhost 服务器上运行一个动态 Web 项目。即(tomcat over eclipse)。但它显示错误 404。它找不到index.jsp 文件。我尝试更改端口,重新检查web.xml,但错误仍然存​​在。那么我应该做些什么来纠正这个错误呢。

这是我的web.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
   <display-name>My_Asap</display-name>


<!-- 
    <servlet>
        <description></description>
        <display-name>MyServlet</display-name>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>asap_pkg.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/servlet/MyServlet</url-pattern>
  </servlet-mapping>
 -->
  <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

这是我的index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <base href="<%=basePath%>">

        <title>My JSP 'index.jsp' starting page</title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">    
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

        <body>
             This is my JSP page. <br>

        <form action ="servlet/MyServlet">
        <input type="submit" value='send'>
        </form>

        </body>
</html>

【问题讨论】:

  • 你的目录结构是什么? index.jsp 驻留在哪里?
  • src->asappkg->myservlet src->dao->db web-inf->lib->web.xml webinf->index.jsp
  • 将 index.jsp 移出 web-inf 文件夹。
  • @SaifAsif 谢谢...它成功了 :)

标签: xml eclipse jsp tomcat servlets


【解决方案1】:

首先在 Eclipse 中转到服务器选项卡,然后按照以下步骤操作:-

1>右击Tomcat,然后点击属性

2>点击切换位置就ok了。

3>双击Tomcat

4> 在服务器位置选项卡中选择“使用 Tomcat 安装”选项。

然后重启Tomcat

【讨论】:

    猜你喜欢
    • 2021-01-15
    • 1970-01-01
    • 2023-03-21
    • 2013-06-19
    • 2011-01-13
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 2023-03-09
    相关资源
    最近更新 更多