Struts 2.1 Tags 2

struts.xml 代码:

Xml代码 复制代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "struts-2.1.7.dtd" >  
  3. <struts>  
  4.     <constant name="struts.custom.i18n.resources" value="struts2"></constant>  
  5.     <constant name="struts.configuration.xml.reload" value="true"></constant>  
  6.        
  7.     <package name="package1" namespace="/com/rao" extends="struts-default">  
  8.         <action name="tagsAction1" class="com.rao.action.TagsAction1">  
  9.             <result>/success.jsp</result>  
  10.                
  11.         </action>  
  12.     </package>  
  13. </struts>  
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "struts-2.1.7.dtd" >
<struts>
	<constant name="struts.custom.i18n.resources" value="struts2"></constant>
	<constant name="struts.configuration.xml.reload" value="true"></constant>
	
	<package name="package1" namespace="/com/rao" extends="struts-default">
		<action name="tagsAction1" class="com.rao.action.TagsAction1">
			<result>/success.jsp</result>
			
		</action>
	</package>
</struts>

 

 TagsAction1.java 代码:

Java代码 复制代码
  1. package com.rao.action;   
  2.   
  3. import com.opensymphony.xwork2.ActionSupport;   
  4.   
  5. public class TagsAction1 extends ActionSupport {   
  6.     private String userName;   
  7.     public String getUserName() {   
  8.         return userName;   
  9.     }   
  10.     public void setUserName(String userName) {   
  11.         this.userName = userName;   
  12.     }   
  13.   
  14.     @Override  
  15.     public String execute() throws Exception {   
  16.            
  17.         return SUCCESS;   
  18.     }   
  19.   
  20. }  
package com.rao.action;

import com.opensymphony.xwork2.ActionSupport;

public class TagsAction1 extends ActionSupport {
	private String userName;
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}

	@Override
	public String execute() throws Exception {
		
		return SUCCESS;
	}

}

 

 

GlobalNativeAction.java

Java代码 复制代码
  1. package com.rao.action;   
  2.   
  3. import com.opensymphony.xwork2.ActionContext;   
  4. import com.opensymphony.xwork2.ActionSupport;   
  5. /**  
  6.  * 演示的是在Action 中获取国际化资源文件中的内容  
  7.  * @author Administrator  
  8.  *  
  9.  */  
  10. public class GlobalNativeAction extends ActionSupport {   
  11.   
  12.     @Override  
  13.     public String execute() throws Exception {   
  14.         //不带有占位符的获取方法   
  15.         //ActionContext.getContext().put("message", this.getText("welcome"));   
  16.         //带有占位符的获取方法   
  17.         ActionContext.getContext().put("message"this.getText("welcome",new String[]{"raozhiyong","study"}));   
  18.         return "message";   
  19.     }   
  20.   
  21. }  
package com.rao.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
/**
 * 演示的是在Action 中获取国际化资源文件中的内容
 * @author Administrator
 *
 */
public class GlobalNativeAction extends ActionSupport {

	@Override
	public String execute() throws Exception {
		//不带有占位符的获取方法
		//ActionContext.getContext().put("message", this.getText("welcome"));
		//带有占位符的获取方法
		ActionContext.getContext().put("message", this.getText("welcome",new String[]{"raozhiyong","study"}));
		return "message";
	}

}

 

 

struts2_zh_CN.properties

 

 

welcome      全局范围:{0},这是一个中文的国际化资源文件,欢迎你的使用{1}!!!

 

GlobalNativeAction_zh_CN.properties

 

 

welcome      Action范围:{0},这是一个中文的国际化资源文件,欢迎你的使用{1}!!!

 

package_zh_CN.properties

 

 

welcome      package范围:{0},这是一个中文的国际化资源文件,欢迎你的使用{1}!!!

 

Sex.java

 

 

Java代码 复制代码
  1. package com.rao.bean;   
  2.   
  3. public class Sex {   
  4.     private int id;   
  5.     private String name;   
  6.        
  7.     public Sex(int id, String name) {   
  8.         super();   
  9.         this.id = id;   
  10.         this.name = name;   
  11.     }   
  12.        
  13.     public int getId() {   
  14.         return id;   
  15.     }   
  16.     public void setId(int id) {   
  17.         this.id = id;   
  18.     }   
  19.     public String getName() {   
  20.         return name;   
  21.     }   
  22.     public void setName(String name) {   
  23.         this.name = name;   
  24.     }   
  25.   
  26. }  
package com.rao.bean;

public class Sex {
	private int id;
	private String name;
	
	public Sex(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

}

 

 

UserBean.java

 

Java代码 复制代码
  1. package com.rao.bean;   
  2.   
  3. import java.io.Serializable;   
  4.   
  5. public class UserBean implements Serializable{   
  6.   
  7.     private static final long serialVersionUID = 1L;   
  8.     public UserBean() {}   
  9.        
  10.     private Integer userId;   
  11.     private String userName;   
  12.     public Integer getUserId() {   
  13.         return userId;   
  14.     }   
  15.     public void setUserId(Integer userId) {   
  16.         this.userId = userId;   
  17.     }   
  18.     public String getUserName() {   
  19.         return userName;   
  20.     }   
  21.     public void setUserName(String userName) {   
  22.         this.userName = userName;   
  23.     }   
  24.   
  25. }  
package com.rao.bean;

import java.io.Serializable;

public class UserBean implements Serializable{

	private static final long serialVersionUID = 1L;
	public UserBean() {}
	
	private Integer userId;
	private String userName;
	public Integer getUserId() {
		return userId;
	}
	public void setUserId(Integer userId) {
		this.userId = userId;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}

}

 

 

MyComparator.java

 

 

Java代码 复制代码
  1. package com.rao.comparator;   
  2.   
  3. import java.util.Comparator;   
  4.   
  5. public class MyComparator implements Comparator<Integer> {   
  6.   
  7.     public int compare(Integer o1, Integer o2) {   
  8.         int c = o1.compareTo(o2);    
  9.         return c;//可以完成顺序排序   
  10.         //return -c;//可以完成倒序排序   
  11.     }   
  12. }  
package com.rao.comparator;

import java.util.Comparator;

public class MyComparator implements Comparator<Integer> {

	public int compare(Integer o1, Integer o2) {
		int c = o1.compareTo(o2); 
		return c;//可以完成顺序排序
		//return -c;//可以完成倒序排序
	}
}

 

 运行结果,附上图片:

 



 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值