我有一個基本的servlet。Web.xml導致Tomcat7失敗
我使用tomcat 7來運行它。
服務器包含3個文件:
file.jsp - 打印日期
WebController - 該servlet。
web.xml - 配置文件。
的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>file.jsp</servlet-name>
<jsp-file>file.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>file.jsp</servlet-name>
<url-pattern>/about</url-pattern>
</servlet-mapping>
</web-app>
當我從web.xml
文件中刪除<servlet>
和<servlet-mapping>
,該servlet運行良好。
當web.xml
是如以上所述,我發現了以下錯誤消息:
'Staring Tomcat v7.0 Server at localhost' has encountered a problem.
Server Tomcat v7.0 Server at localhost failed to start.
我使用蝕。我的web.xml
文件有什麼問題?提前致謝!
編輯:
這是我的項目:
更新:
當前版本的web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>file.jsp</servlet-name>
<jsp-file>/file.jsp</jsp-file>
</servlet>
<servlet>
<servlet-name>WebController</servlet-name>
<servlet-class>WebController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>file.jsp</servlet-name>
<url-pattern>/about</url-pattern>
</servlet-mapping>
</web-app>
可能重複:http://stackoverflow.com/questions/6642745/web-xml-ignoring-main-jsp-file 你在哪裏放jsp文件 – phury
@ph。在WEB-INF文件夾中,jsp文件與'web.xml'位於同一個文件夾中。 – Billie