gpt4 book ai didi

Eclipse 不渲染 jsf?

转载 作者:行者123 更新时间:2023-11-28 22:02:51 24 4
gpt4 key购买 nike

只有 tomcat 服务器才能正确显示 .jsf 页面。当我尝试通过 Eclipse 添加项目并查看和测试时,它不会呈现 .jsf 代码,而是将其显示为源代码。我为 tomcat 配置了 eclipse,它工作正常但无法获取 .jsf 页面来呈现它只是在通过 eclipse 添加到服务器时显示源代码但是如果我导出 .war 文件并在 tomcat/webapps 上运行它然后它工作正常。

来自 eclipse 的源代码示例:

<?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:h="http://java.sun.com/jsf/html">
<h:head>
<title>PCC Accounts Login</title>
</h:head>
<h:body>
<h:outputStylesheet name="style.css"></h:outputStylesheet>
<h:outputText>testing output text tag WITHOUT using value attributeHELLo ????</h:outputText>
<h:outputText value="testing outputText WITH using the value attribute" />
<h:form>
<h:inputText id="user_id" title="User Name" value="User Name" action="#{loginBean.setUsername}">User Name</h:inputText>
<h:inputText id="password" title="Password" value="Password" action="#{loginBean.setPassword}">Password</h:inputText>
<!-- <h:commandButton id="login" value="Login" action="accounts.jsf">Login Now</h:commandButton> -->
<h:commandButton id="login" value="Login" action="accounts.jsf" />
</h:form>
</h:body>
</html>

从eclipse导出并在tomcat上运行的源代码示例:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>PCC Accounts Login</title>
<link type="text/css" rel="stylesheet" href="/assign05_test/javax.faces.resource/style.css.jsf" />
</head>
<body>
<input type="hidden" name="j_idt9" value="j_idt9" />
<input id="j_idt9:user_id" type="text" name="j_idt9:user_id" value="User Name" title="User Name" />
<input id="j_idt9:password" type="text" name="j_idt9:password" value="Password" title="Password" />
<input id="j_idt9:login" type="submit" name="j_idt9:login" value="Login" />
</form>
</body>
</html>

所以,Eclipse 显然没有呈现 JSF 页面,但我将正确的文件添加到 Preferences/Java/BuildPath/UserLibraries。所以我不确定为什么它不起作用,但现在我正在通过导出 .war 然后在 tomcat 服务器上运行它来进行测试,这是一个非常乏味的过程。还有其他人遇到这个问题吗?任何帮助将不胜感激,在此先感谢。

尊敬的,马丁·汉德

最佳答案

在 web.xml 中有这个用于 servlet 映射:

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

改成这样就解决了:

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

有趣的是,它只在尝试通过 Eclipse 运行时影响它,但如果导出 .war 然后添加到 tomcat 中的 /webapps 就没问题了,但这非常乏味尝试开发应用程序时的烦人过程。如果您遇到问题,另请阅读这篇有用的文章 - JSF tags not being rendered as HTML

关于Eclipse 不渲染 jsf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23464637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com