【问题标题】:welcome page after running dynamic web project [duplicate]运行动态 Web 项目后的欢迎页面 [重复]
【发布时间】:2017-01-09 21:10:23
【问题描述】:

我正在尝试在运行动态 Web 项目后显示欢迎页面。 谷歌搜索时,我发现了很多教程,但我找不到解决方案。 我分享:

  • 我项目的structure(我希望页面welcome.xhtml默认显示)。
  • 文件web.xml是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         id="WebApp_ID" 
         version="3.0">
	<display-name>HiSpring</display-name>
	<welcome-file-list>
		<welcome-file>welcome.xhtml</welcome-file>
	</welcome-file-list>
	
	<context-param>
		<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
		<param-value>client</param-value>
	</context-param>
	
	<context-param>
		<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
		<param-value>resources.application</param-value>
	</context-param>
	
	<listener>
		<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
	</listener>
	
	<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>/faces/*</url-pattern>
	</servlet-mapping>
</web-app>

一旦点击HiSpring &gt; Run As &gt; Run on Server,我应该有 这个网址:http://localhost:8080/HiSpring/faces/welcome.xhtml。但是,我得到了http://localhost:8080/HiSpring/。

你能告诉我我错过了什么吗?提前致谢。

【问题讨论】:

  • 你用的是什么技术?
  • 你好@kometen,我正在使用JEE6技术。
  • 嗨@Sofia,谢谢。除了欢迎文件之外,请将它们添加到列表中。像 java、servlet 等。
  • 嗨@kometen,非常感谢您的回复。如果你不介意,你能给我举个例子吗?
  • 很抱歉我不能。不知道你用的是什么技术。在询问之前,您必须提供足够的信息,然后人们才能帮助您。如网络服务器、语言等

标签: spring jsf tomcat7 welcome-file


【解决方案1】:

根据您的 web.xml,tomcat 会查找 /welcome.xhtml,但不知道这可能在 /faces/welcome.xhtml 中。 URL 没问题(如果welcome.xhtml 在/ 中)

可能会有一个更优雅的 JSF 版本(我不是一个 JSF 专家)——我想到的一些可能的解决方案是

  • 将 faces servlet 映射到 *.xhtml 并从路径中删除 /faces/ 部分(您判断这是否是正确的 JSF - 如果不是,请评论,我将删除这部分)
  • 创建一个单独的显式重定向,例如通过一个(非常简单的)index.html(当然,将index.html 声明为另一个欢迎文件),如以下示例:
<html>
 <head><title>Redirection</title>
  <meta http-equiv="refresh" content="2;URL=/faces/">
  <!-- 2 means 2 seconds delay. Change as you like -->
 </head>
 <body>
  <p>redirecting to application. <a href="/faces/">Click here if it doesn't work</a></p>
 </body>
</html>

【讨论】:

    猜你喜欢
    • 2015-06-22
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2013-03-06
    • 1970-01-01
    • 2018-11-28
    • 2012-01-12
    • 1970-01-01
    相关资源
    最近更新 更多