簡體   English   中英

如何配置 web.xml 將 Tomcat 默認登陸頁面更改為 JSP

[英]How to configure web.xml to change Tomcat default landing page to a JSP

我有一個在Tomcat下運行的簡單jsp頁面來顯示一個報告,問題是如何配置web.xml將默認登陸頁面指向這個JSP。

Web.xml 是空的,因此它目前僅在 war 文件的根目錄中命名為 index.jsp 時才有效,但我希望它在 WEB-INF 下具有不同的名稱。 在調用這個之前我也應該先調用一個java類嗎? 我需要檢索數據庫連接而不是在 JSP 中存儲數據庫憑據。 沒有使用像 struts 這樣的 Web 框架。

有兩種方法可以這樣做。

方法一:重新配置web.xml

您可能會在web.xml 中看到類似的內容:

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
</welcome-file-list>

您可以像這樣重新配置登錄頁面:

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

或者你可以像這樣自定義:

<welcome-file-list>
    <welcome-file><TARGETPAGE>.jsp</welcome-file>
    <welcome-file><TARGETPAGE>.html</welcome-file>
    <welcome-file><TARGETPAGE>.html</welcome-file>
</welcome-file-list>

這確保登錄頁面是index.jsp

方法二:重定向

將此添加到您的默認登錄頁面:

<meta http-equiv="refresh" content="0; URL='<TARGETPAGE>.jsp'" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM