0

我在 Eclipse 上有一个使用 Tomcat 的 Web 项目。我的 web.xml 声明了一个欢迎文件

<welcome-file-list>
    <welcome-file>/WEB-INF/pages/testPage.jsp</welcome-file>
</welcome-file-list>

简单的东西,当我通过 eclipse 在本地运行服务器并通过浏览器浏览它时,它会显示我的 testPage.jsp 和按钮,javascript 工作正常。现在 。当我将相同的应用程序原封不动地导出到 WAR,然后将其部署在单独的服务器上并通过同一浏览器浏览到它时,testPage.jsp 显示为纯文本文件,即它没有正确呈现,见下文我只是看到纯文本HTML 文本。如果页面是从在独立的 tomcat 上运行的 WAR 提供的,但从我的 Eclipse 中运行的 Tomcat 提供的页面可以正常工作,为什么我的浏览器不能正确呈现按钮?

    <%@ page contentType="text/html; charset=UTF-8"%>

    <html>
        <head>
            <script type="text/javascript" src="js/testPage.js"></script>
            <script type="text/javascript" src="js/jquery.json-2.3.min.js"></script>
            <script type="text/javascript" src="js/jquery-1.6.4.js"></script>
        </head>

        <body>
            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
                <tr>
                    <td><textarea id="annotationLookupInput"  style="margin-left:5px;width:300px;height:80px;" ></textarea>
                        <input type="submit" name="submit" onclick="annotationLookup()" value="Lookup Annotation ID">
                    </td>
                    <td><textarea id="annotationLookupResult" style="margin-left:5px;width:300px;height:80px;" ></textarea></td>
                </tr>

            </table>

            <table width="100%" border="0" cellspacing="0" cellpadding="0" >
                <tr>
                    <td><textarea id="annotationSaveIDInput"  style="margin-left:5px;width:80px;height:40px;" ></textarea>
                    <td><textarea id="annotationSaveValueInput"  style="margin-left:5px;width:100px;height:40px;" ></textarea>
                        <input type="submit" name="submit" onclick="annotationSave()" value="Save/Update Annotation">
                    </td>
                    <td><textarea id="annotationSaveResult" style="margin-left:5px;width:300px;height:80px;" ></textarea></td>
                </tr>            
            </table>

        </body>
    </html>
4

1 回答 1

1

如果我没记错的话,JSP 应该直接放在项目文件夹中,而不是放在WEB-INF.

您可以尝试并更改 web.xml

<welcome-file-list>
    <welcome-file>testPage.jsp</welcome-file>
</welcome-file-list>
于 2013-08-13T15:22:43.590 回答