随笔 - 55  文章 - 187  trackbacks - 0
<2009年11月>
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345

常用链接

留言簿(12)

随笔分类

随笔档案

groovy

搜索

  •  

最新评论

阅读排行榜

评论排行榜

工程目录


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_2_5.xsd"
    id
="WebApp_ID" version="2.5">
    
<display-name>android</display-name>
    
<welcome-file-list>
        
<welcome-file>index.html</welcome-file>
        
<welcome-file>index.htm</welcome-file>
        
<welcome-file>index.jsp</welcome-file>
        
<welcome-file>default.html</welcome-file>
        
<welcome-file>default.htm</welcome-file>
        
<welcome-file>default.jsp</welcome-file>
    
</welcome-file-list>

    
<!-- 第一 这个过滤器与Struts的核心过滤器协同工作,以便更容易与sitemesh整合 -->
    
<filter>
        
<filter-name>struts-cleanup</filter-name>
        
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
    
</filter>

    
<!-- 第二 sitemesh的过滤器,同时也整合了Freemarker -->
    
<filter>
        
<filter-name>sitemesh</filter-name>
        
<filter-class>org.apache.struts2.sitemesh.FreeMarkerPageFilter</filter-class>
    
</filter>

    
<!-- 第三 struts2过滤器 -->
    
<filter>
        
<filter-name>struts2Filter</filter-name>
        
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    
</filter>


    
<filter-mapping>
        
<filter-name>struts-cleanup</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>
    
<filter-mapping>
        
<filter-name>sitemesh</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>
    
<filter-mapping>
        
<filter-name>struts2Filter</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>

    
<!--
        使FreeMarker模块能够使用strut2标签,使用方式:<#assign
        s=JspTaglibs["/WEB-INF/struts-tags.tld"] />
    
-->
    
<servlet>
        
<servlet-name>JspSupportservlet</servlet-name>
        
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
        
<load-on-startup>1</load-on-startup>
    
</servlet>

    
<servlet>
        
<servlet-name>sitemesh-freemarker</servlet-name>
        
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
        
<init-param>
            
<param-name>TemplatePath</param-name>
            
<param-value>/</param-value>
        
</init-param>
        
<init-param>
            
<param-name>default_encoding</param-name>
            
<param-value>UTF-8</param-value>
        
</init-param>
        
<load-on-startup>1</load-on-startup>
    
</servlet>

    
<servlet-mapping>
        
<servlet-name>sitemesh-freemarker</servlet-name>
        
<url-pattern>/*</url-pattern>
    
</servlet-mapping>

</web-app>

struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
        "http://struts.apache.org/dtds/struts-2.1.dtd"
>
<struts>
    
<constant name="struts.convention.default.parent.package" value="crud-default" />
    
<constant name="struts.convention.package.locators" value="action" />
    
<constant name="struts.convention.package.locators.basePackage" value="org.david.android" />
    
<constant name="struts.convention.result.path" value="/WEB-INF/web" />

    
<!-- 用于CRUD Action的parent package -->
    
<package name="crud-default" extends="convention-default">
        
<!-- 基于paramsPrepareParamsStack,
            增加store interceptor保证actionMessage在redirect后不会丢失 
-->
        
<interceptors>
            
<interceptor-stack name="crudStack">
                
<interceptor-ref name="store">
                    
<param name="operationMode">AUTOMATIC</param>
                
</interceptor-ref>
                
<interceptor-ref name="paramsPrepareParamsStack" />
            
</interceptor-stack>
        
</interceptors>

        
<default-interceptor-ref name="crudStack" />
    
</package>

    
<!-- 
        使用Convention插件,实现约定大于配置的零配置文件风格.
               特殊的Result路径在Action类中使用@Result设定. 
    
-->
</struts>

decorators.xml
<?xml version="1.0" encoding="UTF-8"?>

<decorators defaultdir="/WEB-INF/decorators">
    
<decorator name="main" page="main.ftl">
        
<pattern>/*</pattern>
    
</decorator>
</decorators>

HelloWorldAction.java
package org.david.android.action.user;


public class HelloWorldAction {
    
private String message;
    
public String getMessage() {
        
return message;
    }
    
    
public void setMessage(String message) {
        
this.message = message;
    }
    
    
public String execute(){
        
this.message = "ITdavid";
        
return "success";
    }
}

main.ftl
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>${title}</title>
</head>
<body>
<div>
hello
${body}
</body>
</html>

hello-world.ftl
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="layout" content="main"/>
<title>Insert title here</title>
</head>
<body>
    Hello ${message!}
</body>
</html>


posted @ 2009-11-29 17:05 大卫 阅读(3284) | 评论 (4)编辑 收藏
<?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_2_5.xsd"
    id
="WebApp_ID" version="2.5">
    
<display-name>fmtest</display-name>
    
<welcome-file-list>
        
<welcome-file>index.html</welcome-file>
        
<welcome-file>index.htm</welcome-file>
        
<welcome-file>index.jsp</welcome-file>
        
<welcome-file>default.html</welcome-file>
        
<welcome-file>default.htm</welcome-file>
        
<welcome-file>default.jsp</welcome-file>
    
</welcome-file-list>

    
<context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>/WEB-INF/config/service-context.xml</param-value>
    
</context-param>
    
<listener>
        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    
</listener>

    
<filter>
        
<display-name>Stripes Filter</display-name>
        
<filter-name>StripesFilter</filter-name>
        
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
        
<init-param>
            
<param-name>ActionResolver.Packages</param-name>
            
<param-value>net.sourceforge.stripes.examples</param-value>
        
</init-param>
        
<init-param>
            
<param-name>Interceptor.Classes</param-name>
            
<param-value>net.sourceforge.stripes.integration.spring.SpringInterceptor</param-value>
        
</init-param>
    
</filter>
    
<filter-mapping>
        
<filter-name>StripesFilter</filter-name>
        
<servlet-name>StripesDispatcher</servlet-name>
    
</filter-mapping>

    
<servlet>
        
<servlet-name>StripesDispatcher</servlet-name>
        
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
        
<load-on-startup>1</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>StripesDispatcher</servlet-name>
        
<url-pattern>*.action</url-pattern>
    
</servlet-mapping>

    
<servlet>
        
<servlet-name>Freemarker</servlet-name>
        
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
        
<init-param>
            
<param-name>TemplatePath</param-name>
            
<param-value>/</param-value>
        
</init-param>
        
<init-param>
            
<param-name>template_update_delay</param-name>
            
<param-value>0</param-value> <!-- 0 is for dev only! Use higher value otherwise. -->
        
</init-param>
        
<init-param>
            
<param-name>DefaultEncoding</param-name>
            
<param-value>utf-8</param-value>
        
</init-param>
        
<load-on-startup>1</load-on-startup>
    
</servlet>
    
<servlet-mapping>
        
<servlet-name>Freemarker</servlet-name>
        
<url-pattern>*.ftl</url-pattern>
    
</servlet-mapping>

</web-app>
posted @ 2009-11-25 15:45 大卫 阅读(1746) | 评论 (2)编辑 收藏
解决FreeMarker中文乱码问题。
在web.xml中配置如下:
<servlet>
    
<servlet-name>Freemarker</servlet-name>
    
<servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
    
<init-param>
        
<param-name>TemplatePath</param-name>
        
<param-value>/</param-value>
    
</init-param>
    
<init-param>
        
<param-name>template_update_delay</param-name>
        
<param-value>3600</param-value> <!-- 0 值仅用于开发环境,生产环境请设置为3600或者更大。 -->
    
</init-param>
    
<init-param>
        
<param-name>DefaultEncoding</param-name> <!-- 解决中文编码问题 -->
        
<param-value>utf-8</param-value>
    
</init-param>
    
<load-on-startup>1</load-on-startup>
</servlet>
--------------------

    PES准高手
posted @ 2009-11-25 15:02 大卫 阅读(5057) | 评论 (1)编辑 收藏