免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1291 | 回复: 0
打印 上一主题 下一主题

HelloWorld -- 最简单的 STRUTS2 应用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-19 04:01 |只看该作者 |倒序浏览
web.xml 配置


?xml version="1.0" encoding="UTF-8"?>
!--
    Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
    Use is subject to license terms.
-->
web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    display-name>hello/display-name>
    distributable />
    filter>
        filter-name>struts-cleanup/filter-name>
        filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp/filter-class>
    /filter>
    filter-mapping>
        filter-name>struts-cleanup/filter-name>
        url-pattern>/*/url-pattern>
    /filter-mapping>
    filter>
        filter-name>struts/filter-name>
        filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        /filter-class>
    /filter>
    filter-mapping>
        filter-name>struts/filter-name>
        url-pattern>/*/url-pattern>
    /filter-mapping>
   
    welcome-file-list>
        welcome-file>index.html/welcome-file>
    /welcome-file-list>
/web-app>

struts.xml 配置


?xml version="1.0" encoding="UTF-8" ?>
!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
struts>
    constant name="struts.devMode" value="false" />
    constant name="struts.action.extension" value="html" />
    package name="eicp" namespace="/" extends="struts-default">
        action name="index" class="HelloWorld">
            result name="sucess">/resource/index.jsp/result>
        /action>
    /package>
/struts>

HelloWorld 类

public class HelloWorld {
   
    private static final String Message="Hello World";
   
    private static final String SUCCESS = "sucess";
   
   
    public String getMessage() {
        return Message;
    }
   
    public String execute ( ) {   
            
            return SUCCESS;
   
        }
    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    }
}

index.jsp 使用的视图文件

%@taglib prefix="s" uri="/struts-tags" %>
?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">
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
title>Insert title here/title>
/head>
body>
s:property value="getMessage()"/>
a href="">index/a>
br/>
/body>
/html>


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/8660/showart_467628.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP