运行JSF"Hello World"时出现奇怪的行为 [英] Strange behaviour while running JSF "Hello World"
问题描述
在服务器上运行我的JSF"Hello World"时,出现文件下载"消息框,其中显示您是否要保存此文件,或在线查找要打开的程序",它具有三个选项:查找,保存和取消.当我单击查找"时,显示以下消息
When running my JSF "Hello World" in server I get a File download message box which says "do you want to save this file, or find a program online to open it" which has three options find, save and cancel. When I click on 'find' following message is shown
"Windows具有有关此MIME类型的以下信息.此页面将帮助您找到打开文件所需的软件.
"Windows has the following information about this MIME type. This page will help you find software needed to open your file.
MIME类型:application/xhtml xml
MIME Type: application/xhtml xml
说明:未知
Windows无法识别此MIME类型."
Windows does not recognize this MIME type."
我的xhtml是
<?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 lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Insert title here</title>
</h:head>
<h:body>
<f:view>
<h:outputText value="Hello World"></h:outputText>
</f:view>
</h:body>
</html>
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_2_5.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>hospital</display-name>
<welcome-file-list>
<welcome-file>login.xhtml</welcome-file>
</welcome-file-list>
<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>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
如果我运行该特定的xhtml文件,则该文件将显示在IE中.但是刷新IE后,将显示对xhtml文件的任何更新.
If I run that particular xhtml file then its shown in IE. But any update to xhtml file will will be shown after refreshing the IE.
我正在使用Eclipse-Helios IDE,Glassfish Web服务器.预先感谢
I am using Eclipse-helios IDE, Glassfish webserver. Thanks in advance
推荐答案
MSIE确实不支持application/xhtml+xml
的内容类型.该页面的内容类型应为text/html
(您可以使用HTTP/Web开发人员工具验证该内容).但这应该已经通过默认的JSF/Facelets配置完成了.您似乎并未在给定代码中的任何地方覆盖内容类型.一种方法是使用<f:view>
标签.另一种方法是调用 HttpServletResponse#setContentType()
在某些网络过滤器中.或者,完全不同的是,此事之后可能是由Web服务器本身或该行中的某些代理完成的.
MSIE does indeed not support the content type of application/xhtml+xml
. The page should be served with a content type of text/html
(you can verify that with HTTP/web developer tools). But that should already be done by default JSF/Facelets configuration. You don't seem to have overridden the content type anywhere in the given code. One of the ways is defining it using the contentType
attribute of the <f:view>
tag. Another way is calling HttpServletResponse#setContentType()
in some web filter. Or, completely different, perhaps it's been done afterwards by the webserver itself or by some proxy in the line.
这篇关于运行JSF"Hello World"时出现奇怪的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!