2013-03-01 23 views
1

我创建了一个Eclipse动态Web项目,在WEB-INF文件夹回到Home.jsp蚀动态Web项目的默认起始页

我使用的服务器的Tomcat 7.0.35

的名称该项目是Pilot_1,我有当URL模式是触发一个servlet /家

@WebServlet(description = "Initalizes the table", urlPatterns = { "/home" }) 

我想指定的URL,这样每次我按项目>运行>在服务器上运行,网址是专localhost:8080/Pilot_1/home(同时触发servlet和jsp页面)。

我试图改变上下文根只是“Pilot_1”,这使URL“本地主机:8080/Pilot_1”,不触发这个servlet

我试图改变上下文根“Pilot_1 /家” ,它给出了URL“localhost:8080/Pilot/1/home /”,额外的'/'确保servlet不会触发

我尝试将Context Root更改为“home”, URL“localhost:8080/home /”,再次,额外的'/'确保servlet不会触发

我一直在玩URL和它似乎是唯一的时间当URL是“localhost:8080/Pilot_1/home”时,servlet被触发的是

有没有解决方法?

这是我的web.xml

<welcome-file-list> 
<welcome-file>index.jsp</welcome-file> 
<welcome-file>default.jsp</welcome-file> 
<welcome-file>home.jsp</welcome-file> 

回答

4

请与上下文根不乱。相反,转到web.xml文件并更改welcome-file-list

<welcome-file-list> 
    <!-- note that THIS IS NOT home.jsp, just home (the URL mapping of your servlet) --> 
    <welcome-file>home</welcome-file> 
</welcome-file-list> 

顺便说一句,恢复你已经尽到应用的上下文根的任何变化。

例如,请参阅this answer

+0

我刚刚添加了编辑以包含我的web.xml映射的欢迎文件。 – naddnan 2013-03-01 19:46:49

+0

我恢复了上下文根目录为默认值(Pilot_1),并根据Luiggi的评论调整了我的web.xml,但现在运行时URL为“localhost:8080/Pilot_1”,没有任何内容显示出来。看起来,home.jsp页面甚至不会被读取。 – naddnan 2013-03-01 19:51:10

+0

你应该有'http:// localhost:8080/Pilot_1 /',清理并构建你的项目并重新部署它。另外,确保你在Servlet的'doGet'方法中进行了前进。 – 2013-03-01 19:52:06