struts.xml 代码:
- <?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>
<?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 代码:
- 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;
- }
- }
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
- 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";
- }
- }
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
- 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;
- }
- }
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
- 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;
- }
- }
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
- 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;//可以完成倒序排序
- }
- }
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;//可以完成倒序排序
}
}
运行结果,附上图片: