【问题标题】:eclipse dynamic web project default start pageeclipse动态web项目默认起始页
【发布时间】:2013-02-16 10:00:10
【问题描述】:

我创建了一个eclipse动态web项目,home.jsp在WEB-INF文件夹中

我使用的服务器是Tomcat 7.0.35

项目的名称是 Pilot_1,我有一个 servlet,它在 URL 模式为 /home 时触发

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

我想指定 URL,这样每次我按 Project > Run > Run on Server 时,URL 就是 localhost:8080/Pilot_1/home(同时触发 servlet 和 jsp 页面)。

我尝试将 Context Root 更改为仅“Pilot_1”,这会提供 URL“localhost:8080/Pilot_1”并且不会触发 servlet

我尝试将 Context Root 更改为“Pilot_1/home”,这提供了 URL“localhost:8080/Pilot/1/home/”,额外的“/”确保 servlet 不会触发

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

我一直在使用 URL,似乎唯一一次触发 servlet 是当 URL 为“localhost:8080/Pilot_1/home”时

有什么解决办法吗?

这是我的 web.xml

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

【问题讨论】:

    标签: java eclipse jsp servlets


    【解决方案1】:

    不要乱用上下文根。相反,转到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

    【讨论】:

    • 我刚刚添加了编辑以包含我的 web.xml 映射为欢迎文件。
    • 我将上下文根恢复为默认值 (Pilot_1) 并根据 Luiggi 的评论调整了我的 web.xml,但现在运行时 URL 为“localhost:8080/Pilot_1”,但没有任何显示。似乎 home.jsp 页面甚至不再被读取。
    • 您应该拥有http://localhost:8080/Pilot_1/,清理并构建您的项目并重新部署它。另外,请确保您在 Servlet doGet 方法中进行了转发。
    • 我确实有。但是现在网页是空白的。 home.jsp 和 servlet 都不会被触发。
    • @user2076874 请检查我答案中的链接,它不是用于装饰目的 =\ ,我表明我在doGet 方法中转发到所需的页面。
    猜你喜欢
    • 2012-07-22
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    • 2021-06-23
    • 2011-05-20
    • 1970-01-01
    • 2014-10-07
    • 2011-11-08
    相关资源
    最近更新 更多