struts2.0学习笔记-20070511-1

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 >


  

你可能感兴趣的:(struts2.0学习笔记-20070511-1)