标签:
准备好资源文件
对于中文的属性文件,我们编写好后,应该使用jdk提供的native2ascii命令把文件转换为unicode编码的文件。
命令的使用方式如下:<s:textfield name="realname" key="user"/>
配置部署好后可以在jsp页面测试下index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <s:text name="welcome"></s:text> </body> </html>
在action中测试
package struts.test.action; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class NativeAction extends ActionSupport { @Override public String execute() throws Exception { ActionContext.getContext().put("message", this.getText("welcome")); return "success"; } }showInfo.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'showInfo.jsp' starting page</title> </head> <body> ${message } </body> </html>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.custom.i18n.resources" value="csdn" /> <package name="csdn" namespace="/control" extends="struts-default"> <action name="native" class="struts.test.action.NativeAction"> <result name="success">/WEB-INF/page/showInfo.jsp</result> </action> </package> </struts>
标签:
原文地址:http://blog.csdn.net/lindonglian/article/details/46592603