看板 java 關於我們 聯絡資訊
※狀況概述: 我在某個專案內新增一個index.xhtml檔,然後輸入url想要進入該檔案的頁面: http://localhost:8080/TestJPAProject2/index.jsf ※程式碼: web.xml長這樣: <display-name>TestJPAProject2</display-name> <context-param> <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name> <param-value>true</param-value> </context-param> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> --------------------------------------- index.xhtml:放在TestJPAProject2/src/main/webapp底下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"> <head> <title>Test JSF</title> </head> <body> <h:form> <h:commandButton value="query" action="#{testAction.query()}" /> </h:form> <h:dataTable value="#{testAction.customerList}" var="customer"> <h:column> <f:facet name="header">customerId</f:facet> #{customer.customerId} </h:column> <h:column> <f:facet name="header">name</f:facet> #{customer.name} </h:column> <h:column> <f:facet name="header">countryId</f:facet> #{customer.countryId} </h:column> </h:dataTable> </body> </html> ※錯誤訊息: 頁面顯示 HTTP Status 404 ? Not Found Type Status Report Message /TestJPAProject2/index.jsp Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. ※補充說明:看錯誤訊息似乎是server要找index.jsp但找不到 但我的專案裡面並沒有index.jsp這個檔案,而且輸入的url是index.jsf而非index.jsp 那為何會變成去找index.jsp呢? 那要如何調整,才能讓server去找index.xhtml呢 又若是輸入http://localhost:8080/ 則可以正常進入server預設頁面。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.160.19.54 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/java/M.1609512487.A.F6B.html
fgh81113: url-pattern 只和 request 有關 response 要看你java裡 01/02 13:13
fgh81113: 面寫了怎麼response 01/02 13:13
結果是我WEB.XML放到WEBContent裡面,把web.xml放到這裡面似乎會讀取不到, 所以要先關閉server 然後web.xml應該要移到webapp底下的WEB-INF資料夾裡面,然後WEBContent資料夾整個砍掉 接著對server重新Clean,再將server內的專案移出去再放進來。 重啟server後即可執行該jsf檔。 ※ 編輯: lueichun (1.167.40.176 臺灣), 01/02/2021 14:56:01