[原]MyEclipse 7 添加 MyFaces 1.2.4应用

在创建Web Project时,需要选择J2EE Specification Level,如果选择了J2EE 1.4还好,能使用MyFaces 1.1.5,如果选择了Java EE 5.0,则死活选不了MyFaces,很郁闷,经过n次试验,终于把MyFaces 1.2.4加入到了应用中,步骤如下:

1)新建Web Project,在J2EE Specification Level选项中选择Java EE 5.0。

2)将myfaces-core-1.2.4-bin包中的commons-beanutils-1.7.0.jar,commons-codec-1.3.jar,commons-collections-3.2.jar,commons-digester-1.8.jar,commons-logging-1.1.1.jar复制到WEB-INF\lib文件夹下。

3)下载tomahawk-1.1.6.jar(http://apache.mirror.phpchina.com/myfaces/binaries/tomahawk-1.1.6-bin.zip
)和common-fileupload-1.2.1(http://apache.mirror.phpchina.com/commons/fileupload/binaries/commons-fileupload-1.2.1-bin.zip)和common-el.jar(http://apache.mirror.phpchina.com/commons/el/binaries/commons-el-1.0.zip),然这三个包也复制到WEB-INF\lib文件夹下。

4)web.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns
="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
     
<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>
    
<url-pattern>*.faces</url-pattern>
  
</servlet-mapping>
  
<filter>
    
<filter-name>MyFacesExtensionsFilter</filter-name>
    
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
    
<init-param>
        
<param-name>uploadMaxFileSize</param-name>
        
<param-value>20m</param-value>
        
<!--  <description>Set the size limit for uploaded files.
            Format: 10 - 10 bytes
                    10k - 10 KB
                    10m - 10 MB
                    1g - 1 GB
        </description>
-->
    
</init-param>
</filter>

<!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages  -->
<filter-mapping>
    
<filter-name>MyFacesExtensionsFilter</filter-name>
    
<!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
    
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.)  -->
<filter-mapping>
    
<filter-name>MyFacesExtensionsFilter</filter-name>
    
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>

  
<welcome-file-list>
    
<welcome-file>index.jsp</welcome-file>
  
</welcome-file-list>
</web-app>

5)在WEB-INF\lib下新增faces-config.xml,如下:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi
="http://www.w3.org/2001/XInclude"
 xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

</faces-config>

6)新建一个测试页面,模板选择JSF模板

在合适的位置添加如下代码:

<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %> 

在<f:view></f:view>中间插入测试代码:

<h:form>
    
<t:outputLabel id="a" value="think8848" />
</h:form>

启动Tomcat,如果不出意外,就应该能正常显示think8848字样了。

原文地址:https://www.cnblogs.com/think8848/p/1285885.html