首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

struts2配备和引用资源文件

2012-10-26 
struts2配置和引用资源文件在struts.xml里面加入:constant namestruts.custom.i18n.resources value

struts2配置和引用资源文件
在struts.xml里面加入:
<constant name="struts.custom.i18n.resources" value="globalMessages" />
如下:
<?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="globalMessages" />  多个配置文件以逗号分割,资源文件不在根目录时,要添加相对路径,value中的值不能带.properties。
<package name="test" namespace="/test" extends="struts-default">
<!-- 国际化支持 -->
<action name="i18n" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="s" uri="/struts-tags" %> 
<%@ page contentType="text/html; charset=UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head> 
<title>test</title>
</head>

<body>
${param.username}
${param.votedate}
<br/>
<s:text name="hello"/>
<br/> 
通过request获取:${requestScope.hello}
</body>
</html>

HelloAction.java里面execute方法可以将hello获取到,并加入大request对象中
public String execute() throws Exception {
this.message="成功登陆";v
  ActionContext.getContext().put("hello", this.getText("hello");
System.out.println(this.getText("hello"));
return "success";
}

热点排行