您的位置:首页 > Web前端 > JavaScript

JSF简单实例及无法正常访问的解决方法(404和The markup in the document preceding the root element must be well-formed. )

2013-12-05 11:01 796 查看
一、HTTP Status 404 - /JSFLoginDemo/userLogin.faces



去除如下红色配置即可正常访问:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="2.5"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!--
此处所有代码都是在使用MyEclipse的Guide过程中产生的配置,所以要根据实际情况进行配置的设置。
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
-->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<!-- 所有的servlet的name为"FacesServlet"的页面都以*.faces访问 -->
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

这样通过“http://localhost:8080/JSFLoginDemo/userLogin.faces”访问到登录页面了。

注意,这里配置“Faces Servlet”的“url-pattern”为“*.faces”,所以访问包含JSF的JSP页面时,应该是“页面名称.faces”。

也就是说,直接访问/userLogin.jsp,若/userLogin.jsp中没有JSF代码一切正常,否则会报
Cannot find FacesContext 错误.。

二、error Traced[line: 1] The markup in the document preceding the root element must be well-formed.



因为所写的jsp文件不符合xhtml规则,命名空间不要在使用@包含:

<%@taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@page contentType="text/html;charset=GB2312"%>
需要将对应的内容转换成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 xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xml:lang="en"
lang="en">
<head>
<title>Index</title>
</head>
<body>

<f:view>
.......//此处省略
</f:view>
</body>
</html>

三、org.apache.jasper.JasperException: /index.jsp(15,33) #{...} is not allowed in template text.



这样,页面就能正常运行了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  JSF
相关文章推荐