随笔 - 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 on 2009-11-29 17:05 大卫 阅读(3286) 评论(4)  编辑  收藏 所属分类: Java

FeedBack:
# re: myAndroid(Struts2+Sitemesh+Freemarker) 2009-11-30 15:48 CoderDream
不错,感谢分享!  回复  更多评论
  
# re: myAndroid(Struts2+Sitemesh+Freemarker) 2009-12-01 12:15 创意礼物创意礼品
谢谢!网上找了好久终于找到了。。。  回复  更多评论
  
# re: myAndroid(Struts2+Sitemesh+Freemarker) 2009-12-02 11:18 apple.shan
跟android有什么关系?  回复  更多评论
  
# re: myAndroid(Struts2+Sitemesh+Freemarker) 2009-12-02 12:24 大卫
@apple.shan
没关系,随便起的名字。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: