为什么此文本不会出现在JSF中? [英] Why does this text not appear in JSF?

查看:79
本文介绍了为什么此文本不会出现在JSF中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下HTML文件:

I have the following HTML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<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>First Example JSF Program</title>
<head>

<body>
   Hello <h:outputText value="Darwin"></h:outputText>!
</body>
</html>

但是输出,应该是"Hello Darwin!"不会出现.只有你好!"出现.为什么是这样?没有错误,我确定它具有所有必要的JAR文件-如果没有,它将引发错误吗?

But the output, expected 'Hello Darwin!' won't appear. Only 'Hello !' appears. Why is this? There are no errors and I'm sure it has all JAR files necessary - if it didn't it would throw an error right?

欢呼

P.S.这是一个HTML 5文件,这有区别吗?

P.S. This is an HTML 5 file, does that make a difference?

推荐答案

如果您在浏览器地址中看到的请求URL与在Webapp的web.xml中定义的FacesServlet<url-pattern>不匹配,并且因此FacesServlet不能完成所有JSF工作.

That can happen if the request URL as you see in browser's address did not match the <url-pattern> of the FacesServlet as definied in webapp's web.xml and hence the FacesServlet wasn't able to do its job of performing all the JSF works.

如果右键单击浏览器中的页面并执行 View Source ,您应该已经注意到JSF <h:outputText>标记是完全未处理的. Web浏览器无法识别JSF标签.它们应该由Web服务器中的FacesServlet处理.它们应该能够生成正确的HTML代码,并且最终的HTML结果完全不应包含任何JSF标记.

If you right click the page in browser and do View Source, you should have noticed that the JSF <h:outputText> tag is completely unprocessed. JSF tags aren't recognized by the webbrowser. They are supposed to be processed by the FacesServlet in the webserver. They are supposed to generate proper HTML code and the final HTML result should not contain any JSF tags at all.

您需要确保在浏览器地址中看到的请求URL与在Webapp的web.xml中定义的FacesServlet<url-pattern>相匹配.想象一下,它像*.jsf一样

You need to make sure that the request URL as you see in browser's address matches the <url-pattern> of the FacesServlet as definied in webapp's web.xml. Imagine that it is *.jsf like as

<url-pattern>*.jsf</url-pattern>

然后,您需要将地址栏中的URL从/some.xhtml更改为/some.jsf.

then you should need to change the URL in the address bar from /some.xhtml to /some.jsf.

或者,您也可以更改web.xml以将FacesServlet直接映射到*.xhtml

Alternatively, you could also just change the web.xml to map the FacesServlet on *.xhtml directly

<url-pattern>*.xhtml</url-pattern>

这样您就不再需要摆弄虚拟URL.

so that you don't need to fiddle with virtual URLs anymore.

对于具有HTML5文档类型的文件,这绝对没有区别.我只删除该XML序言,因为它仅对XHTML doctype有效.另请参见是否可以使用JSF +使用HTML 4/5的Facelets?

As to the file having HTML5 doctype, no that makes absolutely no difference. I'd only remove that XML prolog as that's valid for XHTML doctype only. See also Is it possible to use JSF+Facelets with HTML 4/5?

这篇关于为什么此文本不会出现在JSF中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆