struts2.0學習筆記-20070511-1

          新建類HelloWorld.java:

          package myexample;

          import com.opensymphony.xwork2.ActionSupport;

          /**
           * 
          @author deepbluesea
           * myexample
           *
           
          */

          public class HelloWorld extends ActionSupport{
              
              
          private String message;
              
              
          public static final String MYMESSAGE="HelloWorld.message";

              
          public String getMessage() {
                  
          return message;
              }


              
          public void setMessage(String message) {
                  
          this.message = message;
              }

              
              
          public String execute() throws Exception{
                  setMessage(getText(MYMESSAGE));
                  
          return SUCCESS;
              }

              

          }

          建jsp頁面HelloWorld.jsp
          <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
              pageEncoding
          ="ISO-8859-1"%>
          <%@taglib uri="/struts-tags" prefix="s" %>
          <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
          <html>
          <head>
          <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
          <title>
          <s:text name="HelloWorld.message"></s:text>
          </title>
          </head>
          <body>
          <s:property value="message"/>

          </body>
          </html>


          寫配置文件myexample.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>

             
          <package name="myexample" namespace="/myexample" extends="struts-default">
                
          <action name="HelloWorld" class="myexample.HelloWorld">
                  
          <result>/myexample/HelloWorld.jsp</result>
                
          </action>
             
             
          </package>
          </struts>

          把myexample.xml包含到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.enable.DynamicMethodInvocation" value="false" />
              
          <constant name="struts.devMode" value="true" />

              
          <include file="example.xml"/>
              
              
          <include file="myexample.xml"></include>

              
          <!-- Add packages here -->

          </struts>


            

          posted on 2007-05-11 11:16 deepbluesea 閱讀(274) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2007年5月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導航

          統計

          公告

          MSN:zzlljj8833@hotmail.com lava:5832911

          常用鏈接

          留言簿(1)

          隨筆分類(9)

          隨筆檔案(18)

          文章分類(1)

          文章檔案(1)

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 哈巴河县| 招远市| 会昌县| 松阳县| 色达县| 祁连县| 高安市| 蓝田县| 武汉市| 沙河市| 宁国市| 广安市| 镇原县| 乡宁县| 上杭县| 宁乡县| 衡阳市| 都兰县| 聂荣县| 綦江县| 古蔺县| 孝感市| 许昌县| 庆安县| 屏边| 榕江县| 龙口市| 富锦市| 拜城县| 黎平县| 克山县| 宁强县| 厦门市| 巍山| 万载县| 临桂县| 手游| 阜阳市| 英山县| 开远市| 阿勒泰市|