【发布时间】: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