test
标签:MVC
(转帖)Struts资源文件:Struts Message Resources
转自:http://www.javafan.net/article/20040430102526725.html
页面功能 【加入收藏】 【推荐给朋友】 【字体:大 中 小】 【关闭】
Struts Message Resources
作者:Nick Heudecker 来自:未知
总览
许多刚刚学习Struts的程序员在使用Struts的MessageResources特性的时候会遭遇很多困难。本文将试图阐述MessageResources特性的优点并给出了具体的例子说明它的用法。
作者: Nick Heudecker, System Mobile Inc.
概述
类MessageResources可以使开发者方便地支持多语言,包括支持多时间格式和数字格式。使用资源包的另一个好处是允许开发者将标签字符串集中存储在一个位置,而不是分散在不同的JSP页面里。例如,对于每个用户的名字的标签"First Name" ,我们可以将它写在资源包中,在适当的地方通过Struts标签简单的进行引用:
<bean:write key="label.first.name"/>
这样做将会让你对程序的更改变的简单容易,你不必在每一个JSP页面里更改标签的内容了。
用法
使用消息资源包需要你做下面的事情:
1. 为你想要支持的地方创建一个消息资源包。
2. 配置WEB应用,加载消息资源包。
3. 使用相应的JSP标签加载资源或者...
4. ...在一个Action类中加载资源。
创建资源包
MessageResources 类的默认的实现是一个包含"key=value" 对的文件,下面的一个消息资源包文件的例子。
label.username=Username
label.password=Password
label.first.name=First Name
label.last.name=Last Name
label.email=Email Address
label.phone.number=Phone Number
label.welcome=Welcome back {0} {1}!
error.min.length=The input must be at least {0} characters in length.
error.max.length=The input cannot be longer than {0} characters in length.
大括号包围的整数是对java.text.MessageFormat 类的支持,程序员可以向value字符串中传递参数,对每个value字符串你最多可以传递4个参数。
配置
有两种途径通知Struts你的资源包的位置:web.xml 文件或者struts-config.xml 文件。首先来看web.xml 文件的配置:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>
application
</param-name>
<param-value>
com.systemmobile.example.ApplicationResources
</param-value>
</init-param>
</servlet>
这个配置说明你的资源包的名字是ApplicationResources.properties,它位于com.systemmobile.example 包中。后缀".properties" 是隐含的,你不必显式地写出来。如果你还有另一个资源文件在相同的包中,例如ApplicationResources_fr.properties ,用来支持法语,你只需要象上面定义的那样列出文件名字即可。
定义资源文件的第二中方法(上面已经提到),是在struts-config.xml 文件中配置:
<message-resources parameter="com.systemmobile.example.ApplicationResources"/>
属性parameter 是必须的。和在web.xml文件中配置一样, 需要注意的是文件在包中的位置。
使用struts-config.xml 文件来配置消息资源文件是推荐的做法,因为它更有可扩展性,更灵活。
你可以使用message-resources 标签从不同的资源文件取不同的消息,前提是在配置的时候为不同的资源文件给出不同的key 属性的值。例如: <message-resources key="myResources" parameter="com.systemmobile.example.ApplicationResources"/>
<message-resources key="moreResources" parameter="com.systemmobile.example.MoreApplicationResources"/>
然后你必须这样使用bean:message 标签: <bean:message bundle="moreResources" key="some.message.key"/>
设置属性null 的值为"false" 后,如果某个资源字符串不存在将返回???key??? 而不是仅仅显示null。这样很容易在JSP页面中看到你没有定义的资源,使得内部测试的速度更快。(关于如何从资源文件中获得消息的详细内容参见国际化 一节) <message-resources parameter="com.systemmobile.example.ApplicationResources" null="false"/>
另外,message-resources 标签允许你使用自己实现的MessageResourcesFactory 接口,这不在本文的讨论范围。
资源文件放在哪里
关于资源文件最常见的问题是将资源文件放在WAR文件的哪里。简单的回答是该文件必须放在你的classpath下面,这意味着将资源文件放在一个JAR 文件中,或者放在/WEB-INF/classes 目录极其子目录下。下表给出了资源文件的位置,在message-resources 标签中"parameter" 属性的值以及简短的说明。
Resources Location parameter Value Description
/WEB-INF/classes/ApplicationResources.properties ApplicationResources 文件放在classes 目录下, 该目录在web应用的classpath中.
/WEB-INF/classes/resources/ApplicationResources.properties resources.ApplicationResources 该文件放在"resources" 目录下, 所以包名也就是路径名要给出。
In the app.jar file, in the com.systemmobile.example package/directory. com.systemmobile.example.ApplicationResources 文件在JAR文件中的全路径。
Tags
最常用Struts 标签是bean:message 标签。使用这个标签的"key" 可以从资源文件中读特定的消息资源。你还可以传入四个参数中的一个或全部:
<bean:message key="label.password"/>
<bean:message key="error.min.length" arg0="6"/>
<bean:message key="label.welcome" arg0="Ralph" arg1="Nader"/>
html:message 可以让你向用户显示错误信息(默认)或消息信息,而html:errors 只显示错误信息。很明显,错误信息或消息信息一定要保存在request里,否则就什么也不会显示。这里有一个显示消息信息的例子:
<logic:messagesPresent message="true">
<html:messages id="msg" message="true">
<div class="success">
<bean:write name="msg"/>
</div><br/>
</html:messages>
</logic:messagesPresent>
还有一些标签也有限地支持消息资源,比如html:link。html:link标签通过定义"titleKey" 属性来显示标题文本。许多html 使用 "altKey" 属性从资源文件里获得alternate(替代)文本。
Actions
你还可以在Action 类中使用消息资源文件。Action 类有两个方法得到一个MessageResource 类的实例:
// 返回一个request里的资源文件
protected MessageResources getResources(HttpServletRequest request);
// 返回一个request里的资源文件,
// 该资源文件的标志上<message-resources/> 元素的内容
protected MessageResources getResources(javax.servlet.http.HttpServletRequest request, java.lang.String key);
MessageResources类可以让你从资源文件中得到本地化的消息。The API for MessageResources 可以在资源中找到。比较常用的方法有:
// these methods load a resources key for the given locale
public String getMessage(java.util.Locale locale, java.lang.String key);
public String getMessage(java.util.Locale locale, java.lang.String key,
java.lang.Object arg0);
public String getMessage(java.util.Locale locale, java.lang.String key,
java.lang.Object[] args);
public String getMessage(java.util.Locale locale, java.lang.String key,
java.lang.Object arg0, java.lang.Object arg1)
public String getMessage(java.util.Locale locale, java.lang.String key,
java.lang.Object arg0, java.lang.Object arg1, java.lang.Object arg2);
public String getMessage(java.util.Locale locale, java.lang.String key, java.lang.Object arg0,
java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3);
// these methods load a resources key for the locale retrieved
// from the HttpServletRequest
public String getMessage(java.lang.String key);
public String getMessage(java.lang.String key, java.lang.Object arg0);
public String getMessage(java.lang.String key, java.lang.Object[] args);
public String getMessage(java.lang.String key, java.lang.Object arg0,
java.lang.Object arg1);
public String getMessage(java.lang.String key, java.lang.Object arg0,
java.lang.Object arg1, java.lang.Object arg2);
public String getMessage(java.lang.String key, java.lang.Object arg0,
java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3);
这些返回的字符串可以被设置成request 或 session 的参数并串会表现层。你可能注意到了一些重载方法getMessage(...) 选择了参数Object,而另外一些采用了参数arg0...arg3。这和 bean:message arg0...arg3 属性等价。
除了MessageResources 类,还有一些类使用了资源文件。ActionMessage类被用来从action 向JSP之间传递消息资源中的keys 。消息被用来作为bean 的属性。ActionError, ActionMessage的子类,使用消息资源中的keys 存储验证失败后的错误信息。
国际化
从资源文件中提取一个本地化信息可以由类MessageResources 来处理,或者由它的直接子类PropertyMessageResources类处理。既然类PropertyMessageResources 等经常地被用到,那么我们就来看看它是怎样使用getMessage(Locale, String) 方法来从资源文件中读取消息的。
举例说明:
1. 如果你在ApplicationResources_pt_br.properties (Brazilian Portuguese)中没有发现消息的定义,系统将在ApplicationResources_pt.properties 文件中找,如果ApplicationResources_pt.properties 文件不存在或者也没有该消息,那就去ApplicationResources.properties 文件里查找了。
2. 如果消息找到了,它就被加到本地化的缓存中并返回java.lang.String型数据。
3. 如果消息没有找到,此时如果returnNull 属性被为默认的true,将返回 null。 否则将返回类似 ???key??? 的字符串,key 就是那个被传递的参数。
JSTL
JSTL (JavaServer Pages Standard Tag Library) 的fmt标签最近开始流行起来,用来向JSP中显示资源文件的信息。它能很好地和Struts结合在一起。使用它非常简单,只要下载JSTL 的jar 文件和TLDs 并把它们拷贝到你的应用的正确的位置,然后在web.xml文件中加入下面的内容:
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>ApplicationResources</param-value>
</context-param>
上面的配置是假定你的ApplicationResources.properties文件是放在/WEB-INF/classes 目录下的。 参见above 更多情况。
然后将这个标签库直接放在你的JSP中:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
最后,下面的标签将显示资源文件的内容:
<fmt:message key="label.first.name"/>
还有一个使用fmt 标签获得资源的例子。(注意: 该段程序取自Jakarta JSTL examples。)
// loading a resource from a specific bundle and populating a parameter
<fmt:message key="currentTime" bundle="${deBundle}">
<fmt:param value="${currentDateString}"/>
</fmt:message>
// using the forEach iterator to populate paramters
<fmt:message key="serverInfo" bundle="${deBundle}">
<c:forEach var="arg" items="${serverInfoArgs}">
<fmt:param value="${arg}"/>
</c:forEach>
</fmt:message>
结论
在向JSP文件方便地传递消息的同时,Struts使用消息资源文件还帮助我们创建国际化的Web应用。我们既可以使用正在快速发展中的JSTL标签,也可以使用Struts标签,或直接在action中得到一条具体的消息。我希望这篇文章为您阐明了一些Struts中常用的但有时会混淆的东西。
关于作者
Nick Heudecker 是一位软件开发人员,具有6年的企业应用的开发经验。 他所在的公司, System Mobile, Inc.,专门从事应用集成,定制软件开发和无线应用。 他还是Sun认证JAVA程序员,现在居住在Ann Arbor, Michigan。
资源
下面的资源也许对您了解更多的关于Struts资源文件有帮助:
JavaDoc for the classes of interest:
java.util.ResourceBundle
java.util.Locale
org.apache.struts.util.MessageResources
org.apache.struts.action.ActionError
org.apache.struts.action.ActionMessage
Ted Husted's Struts Tips: Very handy advice, especially for resource bundle usage.
Struts Home Page
Struts-User Mailing List Archive: Many people use Struts, so there is a very good chance that your question has be answered already. Please use all available resources before asking your question on the mailing list.
JSTL Homepage and the Jakarta JSTL Implementation
注意事项
Packages are just directory structures used to avoid naming conflicts. If you put a message bundle in a directory named resources under /WEB-INF/classes, this is the equivalent of putting the file in a package named resrouces. While basic, this point seems to trip up many new programmers.
页面功能 【加入收藏】 【推荐给朋友】 【字体:大 中 小】 【关闭】
Copyright © 2003 - 2005 JavaFan.NET All Rights Reserved
Setup logging with Log4j using Struts 1.2.4 on Tomcat 4.1.3
在用中文搜索不到你想要东西时(http://www.learndiary.com/disDiaryContentAction.do?searchDiaryID=1343&goalID=1343&naviStr=a10a60a0167),就用英文吧,有时给你十分满意的答案。昨天,花了许多时间来搜struts下log4j的使用,找到的答案还是没有能解决问题。今天,就用“struts log4j”两个关键字,一下就找到了我要找的东西:)
转自:http://www.mobilefish.com/developer/struts/struts_quickguide_log4j.html
Setup logging with Log4j using Struts 1.2.4 on Tomcat 4.1.3.
Information:
none
Operating system used:
Windows XP Home Edition Version 5.1 SP 2
Software prerequisites:
Log4j 1.2.9
Struts 1.2.4
Tomcat 4.1.3
Procedure:
Download and unzip Log4j.
In the unzipped log4j directory copy file C:\Tools\logging-log4j-1.2.9\dist\lib\log4j-1.2.9.jar to your Struts project: <my_project>\WEB-INF\lib\log4j-1.2.9.jar
Create a log4j.properties file.
As an example you can put the following lines in the log4j.properties file:
log4j.rootLogger=ERROR, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[%5p] %d{mm:ss} (%F:%M:%L)%n%m%n%n
Remark: The ConversionPattern creates the following message:
[ERROR] 02:44 (com.mobilefish.DemoAction execute:95)
This is my message.
Put the log4j.properties file in the following location:
<my_project>\WEB-INF\classes\log4j.properties
Note: In some situations the log4j.properties can not be located by the application server. To find out if this is the case set the -Dlog4j.debug=true.
In the quick guide "Loading the log4j.properties file" serveral solutions are mentioned how to solve this problem.
Add the following lines in your Java code:
package com.mobilefish;
// Please note the following: Struts 1.2.4 uses commons-logging
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class DemoAction extends Action {
private static Log log = LogFactory.getLog("com.mobilefish.DemoAction");
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
log.debug("This is my debug message.");
log.info("This is my info message.");
log.warn("This is my warn message.");
log.error("This is my error message.");
log.fatal("This is my fatal message.");
}
}
Start the application server and run your web application.
Because log4j.rootLogger=ERROR (see log4j.properties file), the following messages are displayed in the console:
[ERROR] 23:35 (DemoAction.java:execute:69)
This is my error message.
[FATAL] 23:35 (DemoAction.java:execute:69)
This is my fatal message.
Note 1. Loggers can be assigned to the following ORDERD levels:
ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF
Note 2. To enable all log messages:
log4j.rootLogger=ALL
Be warned: the struts code and your web applications log messages are logged.
Note 3. To disable all log messages:
log4j.rootLogger=OFF
Struts下配置log4j的方法(转帖2篇)
第一篇:转自:http://tech.eyeah.cn/3116/1113/1137/234119733.html
Log4J配置完后,tomcat5启动如此报错。
作 者:程序员(onebelief)
时 间:2005-02-26 12:30:08
log4j:WARN No appenders could be found for logge(org.apache.catalina.session.ManagerBase).
log4j:WARN Please initialize the log4j system properly.
讨教,讨教。
回复人:程序员(onebelief)2005-2-26 13:06:52
没有人知道么!?
回复人: throw new LowSalaryException(me) (kaymo)2005-2-26 14:08:36
一个包,2个配置文件
回复人:程序员(onebelief)2005-2-26 14:14:48
能说详细点儿么!?我是在架struts应用时出现的这个问题。
struts中的log4j怎么初始化!?
谢谢,请教完马上可以给分!
回复人:西门疯雪(bon_jovi)2005-2-26 14:30:51
log4j.jar和commons-logging.jar放到你的web应用底下的lib中。
在classes下建立两个配置文件commons-logging.properties和log4j.properties
commons-logging.properties里就一行,org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JCategoryLog说明用的是log4j。
启动tomcat就可以了。
你的类里面写日志都是调用的apache的接口,以后换其他日志系统也方便。
回复人:程序员(onebelief)2005-2-26 14:33:18
非常感谢
第二篇:转自:http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=4267&tstart=450
回复: 5 页数: 1
gyokuho [普通用户]
发帖数: 9
活跃积分: 11
技术积分: 0
可用币值: 11
注册时间: 2002-9-4
用户状态:正常
请教:Weblogic/Struts/Log4J 环境下,log destination(appender) 配置问题
提交时间: Jun 9, 2003 2:04:03 AM 引用 回复 发消息
我用 Weblogic 7.0, Struts 1.1, commons-logging.properties 中只有一句:
org.apache.commons.logging.Log=
org.apache.commons.logging.impl.Log4JLog
这样,输出到确省的 System.err去了。怎样配置才能指定输出到一个log文件?
查资料后,好像有:
1, -Dlog4j.configuration=Log4JLog.properties
2, 然后在 Log4JLog.properties 中写一些key=value。
什么的,在我的环境中试验后没有成功。请问具体需要怎样做才解决问题?
此文被gyokuho在2003/06/09 16:14:48修改!
--------------------------------------------------------------------------------
bea_ora [普通用户]
发帖数: 222
活跃积分: 225
技术积分: 3
可用币值: 240
注册时间: 2003-3-26
用户状态:正常
Re:请教:Weblogic/Struts/Log4J 环境下,log destination(appender) 配置问题
提交时间: Jun 10, 2003 4:26:47 AM 引用 回复 发消息
log4j里面有一个
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=example.log
log4j.appender.R.MaxFileSize=100KB
可以把log写到里面,具体的
你查一下log4j API 和
http://www.jfsys.com/main/service/service_log4j.htm
资料吧
此文被bea_ora在2003/06/09 20:31:02修改!
--------------------------------------------------------------------------------
gyokuho [普通用户]
发帖数: 9
活跃积分: 11
技术积分: 0
可用币值: 11
注册时间: 2002-9-4
用户状态:正常
Re:请教:Weblogic/Struts/Log4J 环境下,log destination(appender) 配置问题
提交时间: Jun 11, 2003 4:30:25 AM 引用 回复 发消息
多谢回复。
我在Log4j 的主页上也看到了这样的例子,但是自己试了几次,没有成功。
我不知道那些个设置应该放在哪个properties文件中,这个properties 文件
又应该放在什么位置。
希望做成功的同志给与指导。
--------------------------------------------------------------------------------
xutong [普通用户]
发帖数: 16
活跃积分: 15
技术积分: 1
可用币值: 10
注册时间: 2004-6-11
用户状态:正常
Re: 请教:Weblogic/Struts/Log4J 环境下,log destination(appender) 配置问题
提交时间: Oct 25, 2005 4:01:05 PM 引用 回复 发消息
../WEB-INF/class
--------------------------------------------------------------------------------
fengw [普通用户]
发帖数: 692
活跃积分: 695
技术积分: 60
可用币值: 590
注册时间: 2003-7-18
用户状态:正常
Re: 请教:Weblogic/Struts/Log4J 环境下,log destination(appender) 配置问题
提交时间: Oct 25, 2005 4:47:14 PM 引用 回复 发消息
需要在类路径下添加 log4j.properties文件。
下面是文件的内容,这个我就简单写了点,需要扩展的话查文档
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug,stdout
log4j.logger.com=warn,stdout
--------------------------------------------------------------------------------
让开,让开~~~~~~~
╭══╮
╭╯ΘΘ║
╰⊙═⊙╯。oо○-俺的灌水车来了!!
ttoc [普通用户]
发帖数: 58
活跃积分: 57
技术积分: 0
可用币值: 57
注册时间: 2005-8-27
用户状态:正常
Re: 请教:Weblogic/Struts/Log4J 环境下,log destination(appender) 配置问题
提交时间: Oct 25, 2005 4:55:36 PM 引用 回复 发消息
log4j.rootLogger=INFO,stdout,file
log4j.logger.com.common.utility.MailSend=ERROR,A1
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %r [%t] %5p [%F:%L] - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=c:/aaa.txt
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %r [%t] %5p [%F:%L] - %m%n
log4j.appender.rolling.layout=org.apache.log4j.PatternLayout
log4j.appender.rolling.layout.ConversionPattern=%d %r [%t] %5p [%F:%L] - %m%n
log4j.appender.rolling=org.apache.log4j.RollingFileAppender
log4j.appender.rolling.File=c:\comics.log
#log4j.appender.rolling.File=/usr/local/tomcat/logs/comics.log
log4j.appender.rolling.MaxFileSize=5120KB
log4j.appender.rolling.MaxBackupIndex=10
log4j.appender.A1=org.apache.log4j.RollingFileAppender
log4j.appender.A1.File=c:\mail.log
#log4j.appender.A1.File=/usr/local/tomcat/logs/comics.log
log4j.appender.A1.MaxFileSize=500KB
log4j.appender.A1.MaxBackupIndex=50
log4j.appender.A1.Append=true
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} - [%p] [%C{1}] - %m%n
(转帖)webwork并入struts团队了!
对学习Struts的朋友是一个利好的消息,正文如下:
webwork并入struts团队了!
来源:http://www.javaeye.com/viewtopic.php?t=17242&postdays=0&postorder=asc&start 发表时间:2005-11-29 09:29
WebWork joining Struts
Yes, it's true. The WebWork development team (Jason and I) have been working with the Struts development team (Don Brown and Ted Husted) and have come to the conclusion that the best thing for Java community would be to merge WebWork in to Struts.
Read Ted's email here, but the gist of it is this: WebWork is a great technology, and Struts is a great community. It's a perfect match and bringing the two together will only be better for WebWork and Struts users alike. The only down side for me is that I'll be working less with OpenSymphony, but I believe that is a small price for all the great benefits that come from this merger.
Just to be clear, WebWork is not going away. WebWork 2.2 is still coming out any day now, and there may even be a WebWork 2.3. But new minor/major versions won't be coming out under the WebWork name for much longer. Instead, they will be released under the Struts incubator program with the intent to eventually become Struts Action Framework 2.0.
So don't worry, WebWork 2.1.8, 2.2.1, and other bug fix releases will continue to come out and we will support the WebWork community as long as needed. In addition, we'll make compatibility with both Struts and WebWork a high priority, so future releases may help with that. To be clear: no one is leaving WebWork and it will continue to be supported for a very long time.
With this renewed energy, larger development team, and larger community, the combined efforts of Struts and WebWork will surely make the Struts platform the easiest, fastest, and most powerful Java web framework available. We hope that all the WebWork users and developers are as excited about this as we are and are ready to take WebWork to the next level
原文:http://www.opensymphony.com/webwork/
阅读:321次 〔lanxing〕
版权声明
评论人:lanxing 参与分: 6527 专家分: 181 发表时间: 2005-11-29 09:42 评论
一下文字来自javaeye的管理员 robbin
==========================================================
看到了这个消息以后感觉非常吃惊,所以跟踪相关的link仔细阅读了一下相关的网页,看完以后我认为对于webwork和struts来说这都是一个重大利好的消息。从整个事件来看,并不是单纯的webwork开发团队合并struts团队这么简单,事实上struts1.3和webwork2.2仍然按照原定roadmap继续发展,而两个团队核心开发人员发起一个新的项目Struts Ti,它的readmap是:
引用:
* Ti phase 1 = WebWork 2.2 + Struts 1.x compatibility library and migration tools
* Ti phase 2 = phase 1 + Commons Chain integration + Beehive's Page Flow + simplified annotations + quick development mode
从这个roadmap可以看出来,新项目Struts Ti是以webwork的整体架构为基础,辅以Struts的一些库,并且该项目的四个发起人联名的声明中这样说:
引用:
As some of you know, the underlying idea behind Ti was to use WebWork as the core of Struts Action Framework 2.x. Conceptually, WebWork and Struts 1.x are very similar. We've often said, without embarrassment, that WebWork does many things better than Struts 1.x. Meanwhile, WebWork has the ability to provide a layer of almost full backwards-compatibility for Struts 1.x, and we have already demonstrated we can integrate Beehive's (very cool) Page Flow with WebWork.
这段话明白无误的指明新框架是以webwork为core的,并且webwork可以提供一个抽象层,以完全向后兼容Struts1.x,并且struts还可以集成Apache Beehive的Page Flow。
因此,我想那些担心webwork从此消失的人可以打消顾虑了,消失的只是webwork这个名字,和com.opensymphony的package前缀,而webwork的程序架构却不会消失。
对于Struts的使用者来说,Struts虽然拥有一个庞大的使用群体,但是Struts在技术上已经非常落伍,再不进行重大的架构革新,势必要被淘汰。因此,这个事情是Struts开发团队的一次自救的革命,从Struts1.3到Struts Ti的改变如同EJB2到EJB3的改变,旧的Struts1.3的架构被完全抛弃,吸收了更加先进的开源软件和架构之后,推出的新东西。
对于Webwork的使用者来说,获得了更加广泛的用户群体和接受度。并且核心开发团队也得到了壮大,相信未来的新版本推出速度可以更快了,而不是现在这样,对webwork2.2都望穿秋水了。
另外非常值得注意的是,Struts Ti的目标可不止集成Webwork这么简单,看看它的phase 2,集成Beehive的Page Flow,JDK1.5的annotations,目标是Ruby on Rails般的快速开发模式,多么诱人的前景!
============================================================
(转帖)[译]Struts Menu开发向导
哈,网络真是一个好东东,早就想在我们站使用菜单技术,可是我对此不熟悉,这里又有一个现存的东西可以拿来用了。
转自:http://kb.csdn.net/java/Articles/200511/3af84c4b-0aba-47ad-9060-58f81c7592ab.html
正文:
您的位置:CSDN 首页 -> 知识库 -> 文章摘要
[译]Struts Menu开发向导
作者: ∣来源:BlogJava∣原文地址∣2005-11-28
官方英文版向导(http://struts-menu.sourceforge.net/userguide.html)
一、从1.X升级到2.X需要做以下事情:
1、改变你的taglib声明中的URI。
<% at taglib uri="http://struts-menu.sf.net/tag" prefix="menu" %>
2、改变<plug-in>,使用新的包名"net.sf.navigator." 。
<plug-in className="net.sf.navigator.menu.MenuPlugIn">
3、改变你的menu-config.xml文件,使用新的包名"net.sf.navigator." 。
<Displayer name="Simple"
type="net.sf.navigator.displayer.SimpleMenuDisplayer"/>
二、快速开始:
1、下载最新的struts-menu版本;
2、解包到本地目录;
3、下载Tomcat或者其它Servlet容器;
4、把struts-menu.war包放入Tomcat安装目录的wabapps目录下,并重启Tomcat服务。
5、打开htpp://localhost:8080/struts-menu/
三、把Struts Menu整合到你的应用程序中:
Struts Menu能够被轻易的整合到你的Struts应用程序中,它也可以整合到一个非Struts的应用程序中,但是我不喜欢这样做,所以在此没有提供相应的教程。这里将一步步的带你整合这个标签库。
你需要把struts-menu.jar放到你的WEB-INF/lib目录下。然后使用URI标签声明你的JSP文件中想使用的这个标签库。
如果使用Struts Menu 2.1,你还需要 Jakarta's Standard Tag Library JAR包放入你的WEB-INF/lib目录下。下载地址:http://ibiblio.org/maven/taglibs/jars/standard-1.0.4.jar,这个文件包括例程WAR包文件和二进制发布包。
1、放入struts-menu.jar包到你的应用程序的WEB-INF/lib目录中。
2、在你的struts-config.xml文件中加入plug-in设置。
<plug-in className="net.sf.navigator.menu.MenuPlugIn">
<set-property property="menuConfig"
value="/WEB-INF/menu-config.xml"/>
</plug-in>
3、你将需要在你的应用程序的/WEB-INF/menu-config.xml文件中定义你的菜单,这里提供一个简单的片断:
<Menu name="contactMenu" title="Contact" location="?Contact">
<Item name="email" title="E-Mail" location="?EMail"/>
<Item name="phone" title="Phone" location="?Phone"/>
</Menu>
更多全面的例程,请查看应用程序的web/WEB-INF目录中的menu-config.xml文件,你可以截取一段作为你需要的菜单。完整的属性列表,可以查看MenuBase class's javadocs(http://struts-menu.source......avigator/menu/MenuBase.html)。
4、在你的JSP文件的顶部加入taglib声明:
<% at taglib uri="http://struts-menu.sf.net/tag" prefix="menu" %>
5、在你的JSP文件中要放置菜单的位置加入taglib代码:
<menu:useMenuDisplayer name="TabbedMenu"
bundle="org.apache.struts.action.MESSAGE">
<menu:displayMenu name="Home"/>
<menu:displayMenu name="About"/>
</menu:useMenuDisplayer>
属性name="TabbedMenu"被定义在menu-config.xml文件的顶部:
<Displayer name="TabbedMenu"
type="net.sf.navigator.displayer.TabbedMenuDisplayer"/>
(译注:其实到此步即可在你的JSP文件中添加相应的菜单了,只不过是没有结合Velocity。在menu-config.xml文件的头部可以定义多个Displayer,每个Displayer都有name和type属性,name属性与JSP文件中menu:useMenuDisplayer标签的name属性相对应,即表明使用何种样式,具体的样式定义便在type属性中定义,type属性中是一个class。在menu-config.xml文件中的菜单定义中的name属性则与JSP文件中的menu:displayMenu标签的name属性相对应。)
使用定制的Velocity模版实施你的菜单,你需要整合Velocity到你的WEB应用程序中。如果需要这样做的话,请完成下面的步骤:
1、确定你的menu-config.xml文件有“Velocity”的displayer定义:
<Displayer name="Velocity"
type="net.sf.navigator.displayer.VelocityMenuDisplayer"/>
2、加入Velocity的JARs包到你的WEB-INF/lib目录中,下载velocity-1.4-rc1.jar(http://www.ibiblio.org/ma......y/jars/velocity-1.4-rc1.jar)和velocity-tools-view-1.0.jar(http://www.ibiblio.org/ma......velocity-tools-view-1.0.jar)。
3、加入globalMacros.vm(http://cvs.sourceforge.net/viewcvs.py/*checkout*/struts-menu/navigator/web/WEB-INF/classes/globalMacros.vm?content-type=text%2Fplain&rev=1.1(右键另存为))到你的WEB-INF/lib目录中。
4、改变你的JSP文件中displayer的值为“Velocity”,“config”属性指向一个文件(如config="/templates/tabs.html")或者如果tabs.htm在你的WEB-INF/classes目录中的话,则可设config="tabs.html"。
这里提供了一些使用Velocity的displayer例子,可在sample application(http://demo.raibledesigns.com/struts-menu/index.jsp)中查看。它总是在你的菜单需要的时候显示CSS,JavaScript和图像文件。下面有一些在当前的Struts Menu中用到的Velocity模版的例子的链接:
CoolMenus: Demo(http://demo.raibledesigns......menu/velocity-coolmenu4.jsp),
Template(http://struts-menu.sourceforge.net/templates/coolmenus.html)
NiceTabs: Demo, Template
Tabs: Demo, Template
XTree: Demo, Template
所有相关的有用的文件如果你需要的话都可以在下面的站点上下载:
Images (http://struts-menu.sourceforge.net/menu-images/)
Stylesheets (http://struts-menu.sourceforge.net/styles/)
Scripts (http://struts-menu.sourceforge.net/scripts/)
Templates (http://struts-menu.sourceforge.net/templates/)
更多的基于roles的显示/隐藏菜单的信息,请查看FAQs(http://struts-menu.sourceforge.net/faq.html)。
四、在Struts之外使用Struts Menu:
在2.2版中,Menu Repository能够使用MenuContextListener载入:
<!--
- Loads the menu-config.xml for struts-menu at startup,
- by default from "/WEB-INF/menu-config.xml".
- To override this, add a context-param named "menuConfigLocation"
- web.xml file.
-->
<listener>
<listener-class>net.sf.navigator.menu.MenuContextListener</listener-class>
</listener>
或者如果你使用Spring,甚至更容易。仅仅需要加入下面的部分到你的applicationContext.xml文件中:
<bean id="menu" class="net.sf.navigator.menu.MenuLoader">
<property name="menuConfig">
<value>/WEB-INF/menu-config.xml</value>
</property>
</bean>
<!-- The menuConfig property is an optional attribute. It is set to
/WEB-INF/menu-config.xml by default. -->
感谢Dan Luputan提供MenuLoader类的源代码。
五、从源文件编译:
要从源文件编译这个项目,执行下面的步骤:
1、下载并安装Maven(http://maven.apache.org/);
2、创建一个环境变量MAVEN_HOME指出你的Maven的安装目录,然后添加$MAVEN_HOME/bin到你的PATH变量中;
3、操纵这个目录你可以扩展源代码,执行“maven.jar”创建target/struts-menu.jar。
要展开struts-menu例程,需要下面的步骤:
1、下载和安装Tomcat;
2、创建一个环境变量CATALINA_HOME指出你的Tomcat的安装目录;
3、执行“maven deploy”把应用程序展开到Tomcat中;
4、打开http://localhost:8080/struts-menu在你喜爱的浏览器中。
如果你喜欢使用Eclipse开发项目,请参考此份开发向导(http://struts-menu.sourceforge.net/devguide.html)。
Robin's Java World 2005-11-28 10:15
--------------------------------------------------------------------------------
struts国际化问题(转贴,如有侵权,请告知)
放在这里备忘。
>> 欢迎您,客人: 登录 | 注册 | 忘记密码 | 在线 | 搜索 | 帮助 |
论坛全文检索:
【ChinaJavaWorld.com技术论坛】
『 Struts 及 MVC Framework论坛 』 [返回]
[原创]"struts中文问题&quo ...
标记论坛所有内容为已读
>> 『 Struts 及 MVC Framework论坛 』 欢迎您的到来 <<
◆您是本帖第 257 个阅读者◆
* 贴子主题: [原创]"struts中文问题","struts国际化问题"——终极解决方案
baozitou007
信息:
威望: 0
来自: 湖北鄂州
总发贴数: 35 篇
注册日期: 2004/01/17
消息 查看 搜索 好友 邮件 QQ 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
引文
----------------------------------------
----------------------------------------
说实话,你们的方法都做的复杂了,Java本身就支持多国语言编码,不需要写任何程序,可以很简单的
实现。
秘诀就是两点:
1、所有HTML/JSP页面全部采用UTF-8编码
2、客户端浏览器完全支持UTF-8编码
步骤:
1、首先把所有的HTML/JSP的ContentType都设为UTF-8
2、然后对于JSP程序中的非ASCII码提示信息都不应该写在程序里面,都应该放在
application.properties里面统一管理。
3、对HTML用native2ascii工具统一做一次处理,把HTML中的非ASCII码都转换为Unicode编码。
4、针对不同的语言,写不同的application.properties,比如说简体中文是
application_zh_CN.properties,繁体中文是application_zh_TW.properties这样,然后对这些配置信
息文件同样用native2ascii工具处理一次,把非ASCII码统统转为Unicode编码。
5、在Servlet的request.getCharacterEncoding()获得客户端的操作系统默认编码,然后set到Struts
的HTTPSession的Locale中。
OK!现在不同的客户访问,就会显示不同的语言版本了。你可以看看此时你的浏览器的字符集,就是
UTF-8。现在你的网站和Google一样了,嘿嘿,其实你有心的话,看看你的浏览器访问Google的时候是
什么字符集吧
切记:所有的HTML/JSP都要设为UTF-8编码,所有的文件中的非ASCII码字符都要用native2ascii工具转
为用ASCII表示的Unicode编码。
----------------------------------------
----------------------------------------
原创
----------------------------------------
上面所述是我从网上下的一篇于中文问题的解决方案,确切的说应该是关于Struts的国际化问题,下面我结合我的实践谈谈具体如何实现Struts的国际化问题,我对理论不是非常精通,我只能完全凭自己的理解和实践来讲述,所以下面讲的内容可能不是非常正确,还请大家原谅。但有一点可以肯定,我通过自己的努力解决了Struts的中文问题,并实现Struts的国际化,其实一切并不复杂,下面是具体步骤:
0.遇到的问题(这些问题也许不会同时出现)
a.中文数据从数据库中到jsp中后就变成了"????"
b.做好的中文properties文件,其中的中文value在页面显示乱码
c.jsp文件中的中文到浏览器后显示时也是乱码(建议不要在jsp文件中输入中文,尽量放在properties文件中)
d.由jsp传给bean的中文值,再由bean传回页面又是乱码
e.当更换本地浏览器的语言选项时,Web应用程序不能自动根据你的locale选择合适的*.properties文件。导致Web应用程序不能国际化。
1.环境:
Web服务器: Tomcat 5.0.19
操作系统: Win2000 Server
JVM : jdk 1.4
数 据 库: Oracle 8.1.7
开发工具: struts studio 5.2 pro for eclipse
2.先将所有*.jsp 网页中开头处加入
<%@ page language="java" contentType="text/html; charset=utf-8" %>
再设置<html:html locale = "true">
3.然后编辑好两个*.properties文件,放在classes文件夹下你指定的地方,这里是放在/web-inf/classes/com/wiley 下,它们分别是:
ApplicationResources.properties (英文资源文件)
ApplicationResources_zh.properties (中文资源文件)
随便用什么工具编写都行啊!
4.将ApplicationResources_zh.properties转码成gb2312。上面引文说要转成UTF-8,结果我试了,不行。转成gb2312就行了,操作是。
将ApplicationResources_zh.properties更名为ApplicationResources_xx.properties
在DOS命令行进入ApplicationResources_xx.properties所在的文件夹
使用命令:native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties(至于你为什么会出现“native2ascii不是内部命令”,,请查其它资料,可能你要设置环境变量,因为他是jdk的文件夹bin下的一个应用程序)
5.接下来配置struts-config.xml,很简单,我们加入:
<message-resources parameter="com.wiley.ApplicationResources"/> 就行了;
到此已能解决大多数中文问题。如上面所说的a,b,e 现在打开浏览器,选择菜单:工具》internet选项》语言,将“中文-中国[zh-cn]”删掉,添加一个“英语-英国[zh-gb]”确定后,重启Tomcat,输入网址你就会发现,你的页面的文本信息就会用的是ApplicationResources.properties (英文资源文件)中的内容。如果换回“中文-中国[zh-cn]”,它就会显示ApplicationResources_zh.properties (中文资源文件)中的中文内容。
至于问题“c.jsp文件中的中文到浏览器后显示时也是乱码” 你就要用与第4步类似的方法来重新对*.jsp 文件编码,这时-encoding的参数就要用UTF-8了,如果你用的也是struts studio 5.2 pro for eclipse工具,这一步就免了。它会自动用UTF-8的格式存储。
至于问题“d.由jsp传给bean的中文值,再由bean传回页面又是乱码”的解决,我只是加了个过滤器。
你可以现在web.xml中加入:
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.wiley.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
然后在你指定的包内加个java文件 我放在了/web-inf/classes/com/wiley 里,下面是源代码:
/*
* XP Forum
*
* Copyright (c) 2002-2003 RedSoft Group. All rights reserved.
*
*/
package com.huahang.tj.struts.filters;
import javax.servlet.*;
import java.io.IOException;
/**
* <p>Filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters:</p>
* <ul>
* <li><strong>encoding</strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on
* the <code>ignore</code> initialization parameter. This parameter
* is required, so there is no default.</li>
* <li><strong>ignore</strong> - If set to "true", any character encoding
* specified by the client is ignored, and the value returned by the
* <code>selectEncoding()</code> method is set. If set to "false,
* <code>selectEncoding()</code> is called <strong>only</strong> if the
* client has not already specified an encoding. By default, this
* parameter is set to "true".</li>
* </ul>
*
* <p>Although this filter can be used unchanged, it is also easy to
* subclass it and make the <code>selectEncoding()</code> method more
* intelligent about what encoding to choose, based on characteristics of
* the incoming request (such as the values of the <code>Accept-Language</code>
* and <code>User-Agent</code> headers, or a value stashed in the current
* user's session.</p>
*
* @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>
*
* @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002/04/10 13:59:27 johnwong Exp $
*/
public class SetCharacterEncodingFilter implements Filter {
// ----------------------------------------------------- Instance Variables
/**
* The default character encoding to set for requests that pass through
* this filter.
*/
protected String encoding = null;
/**
* The filter configuration object we are associated with. If this value
* is null, this filter instance is not currently configured.
*/
protected FilterConfig filterConfig = null;
/**
* Should a character encoding specified by the client be ignored?
*/
protected boolean ignore = true;
// --------------------------------------------------------- Public Methods
/**
* Take this filter out of service.
*/
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
/**
* Select and set (if specified) the character encoding to be used to
* interpret request parameters for this request.
*
* @param request The servlet request we are processing
* @param result The servlet response we are creating
* @param chain The filter chain we are processing
*
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet error occurs
*/
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
// Conditionally select and set the character encoding to be used
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
// Pass control on to the next filter
chain.doFilter(request, response);
}
/**
* Place this filter into service.
*
* @param filterConfig The filter configuration object
*/
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else if (value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}
// ------------------------------------------------------ Protected Methods
/**
* Select an appropriate character encoding to be used, based on the
* characteristics of the current request and/or filter initialization
* parameters. If no character encoding should be set, return
* <code>null</code>.
* <p>
* The default implementation unconditionally returns the value configured
* by the <strong>encoding</strong> initialization parameter for this
* filter.
*
* @param request The servlet request we are processing
*/
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}//EOC
到此我遇到的中文问题已全部得到解决,并从中理解到struts的国际化的深刻含义。
我个人觉得struts作为一个功能强大的应用框架,应该早就考虑到它的国际化问题,并在实际应用中不会很复杂,只要我们遵循一些规则,就可以尽情享受struts给我们带来的无穷乐趣。希望以上所述对大家有所帮助。
--------------------------------------------------------------------------------
2004/03/30 09:36am IP: 已设置保密
风行天下
信息:
威望: 0
来自: 北京
总发贴数: 59 篇
注册日期: 2003/04/28
消息 查看 搜索 好友 邮件 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
thanks very much
--------------------------------------------------------------------------------
2004/03/30 12:07pm IP: 已设置保密
zhushilin
kopf43
信息:
威望: 0
来自: 上海
总发贴数: 43 篇
注册日期: 2002/07/24
消息 查看 搜索 好友 邮件 QQ 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
好文章,长见识了
--------------------------------------------------------------------------------
2004/03/30 01:17pm IP: 已设置保密
iamisabird
信息:
威望: 0
来自: 保密
总发贴数: 17 篇
注册日期: 2004/02/21
消息 查看 搜索 好友 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
我想问一下,在步骤2中提到的“非ASCII码提示信息“是指哪些东西
--------------------------------------------------------------------------------
2004/03/30 11:36pm IP: 已设置保密
baozitou007
信息:
威望: 0
来自: 湖北鄂州
总发贴数: 35 篇
注册日期: 2004/01/17
消息 查看 搜索 好友 邮件 QQ 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
这里说的“非ASCII码提示信息”说的是在你的jsp文件中输入不是a,b,c,d......r等ASCII码表中的字符,比如说“中文”,或者是“韩文”等,这都是非“非ASCII码提示信息”例如:
<html:html xhtml="true" locale="true">
<head>
<title>
<bean:message key="app.title" />
</title>
</head>
<body>
看来UTF-8是个好东西!
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr bgcolor="#36566E">
<td height="68" width="48%">
----------------------------------
其中“看来UTF-8是个好东西!”就是我们说的“非ASCII码提示信息”
--------------------------------------------------------------------------------
2004/03/31 09:19am IP: 已设置保密
momocha
信息:
威望: 0
来自: 保密
总发贴数: 59 篇
注册日期: 2003/06/26
消息 查看 搜索 好友 邮件 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
切记:所有的HTML/JSP都要设为UTF-8编码,所有的文件中的非ASCII码字符都要用native2ascii工具转
为用ASCII表示的Unicode编码。
问个问题,你所说的这一步不太明白,是不是每一个包含非ascii的jsp/html文件都要用这个工具转换一个,能说说这个工具吗,谢谢了!!
--------------------------------------------------------------------------------
2004/03/31 03:03pm IP: 已设置保密
baozitou007
信息:
威望: 0
来自: 湖北鄂州
总发贴数: 35 篇
注册日期: 2004/01/17
消息 查看 搜索 好友 邮件 QQ 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
native2ascii -encoding gb2312 jspname.jsp newjspname.jsp
native2ascii这个工具是jdk自带的一个东东,所以如果path都设定正确就可以直接运行了,你可以在$java_home$/bin下找到他。
所以你要设一下系统环境变量:C:\jdk\bin
--------------------------------------------------------------------------------
2004/04/01 10:01am IP: 已设置保密
sdyjmc 头衔: 飞天
信息:
威望: 0
来自: 其它大洋洲
总发贴数: 886 篇
注册日期: 2001/12/21
消息 查看 搜索 好友 主页 QQ ICQ 复制 引用 回复 加到"个人收藏夹"
--------------------------------------------------------------------------------
不知数据库中的编码,在datasource中怎么解决?能够建立pool的时候指定编码?
<set-property property="weblogic.codeset" value="GBK" />
--------------------------------------------------------------------------------
2004/04/01 04:54pm IP: 已设置保密
该主题只有一页 跳转论坛至... ╋Java 2 Platform, Standard Edition (J2SE) 与Java核心技术论坛 |-『 Java语言*初级版 』 |-『 Java语言*高级版 』 |-『 JavaGUI设计 』 |-『 Java安全版块 』 |-『 Java工具安装、配置与使用 』 |-『 Java新技术,新闻,应用与资源等 』╋Java 2 Platform, Enterprise Edition (J2EE) 技术论坛 |-『 JSP/Servlets/JSF 』 |-『 JDBC,JDO 』 |-『 EJB 』 |-『 其他J2EE技术 』╋Java 2 Platform, Micro Edition (J2ME)技术论坛 |-『 J2ME 技术论坛 』╋J2EE 应用服务器 技术论坛 |- 『 BEA WebLogic Platform 技术论坛 』 |-『 IBM WebSphere 技术论坛』 |-『 其他应用服务器技术论坛 』 ╋Web Services和XML技术 |-『 Web Services 技术论坛 』 |-『 XML技术论坛 』╋Apache Jakarta Project技术论坛 |-『 Tomcat技术论坛』 |-『 Struts 及 MVC Framework论坛 』 ╋软件过程管理,建模等 |-『 设计模式 』 |-『 UML 』 |-『 软件测试 』 |-『 软件工程,过程及项目管理 』╋Java相关认证论坛系列 |-『 SCJP认证论坛 』 |-『 Java其他认证 』╋数据库技术 |-『 Oracle&PostgreSQL技术论坛 』╋其他软件开发技术 |-『 C#和.Net技术论坛 』╋操作系统 |-『 操作系统论坛 』╋其他 |-『 休闲乐园 』 |-『 英语学习论坛 』 |-『 求职与招聘 』 |-『 广告论坛 』╋站务建设区 |-『 站务建设 』 |-『 版主专区 』 |-『 论坛公告区 』 |-『 帖子讨论专区 』╋ChinaJavaWorld服务专栏
快速回复主题: [原创]"struts中文问题","struts国际化问题"——终极解决方案
输入用户名和密码: 用户名: 没有注册? 密码: 忘记密码?
上传附件或图片 (最大容量 300KB) 支持类型:----------gifjpgbmpzippngswfdoctxthtmhtmlgzrartarsxw
选项
使用 LB5000 标签?
显示您的签名?
有回复时使用邮件通知您?
[使用 Ctrl+Enter 直接提交贴子]
顶端 加到"个人收藏夹" 主题管理: 总固顶 | 取消总固顶 | 区固顶 | 取消区固顶 | 固顶 | 取消固顶 |
精华 | 取消精华 | 提升 | 锁定 | 解锁 | 删除 | 删除回复 | 移动 |
--------------------------------------------------------------------------------
© 中文版权所有: Java开发者 版本: LB5000MX 2.00
程序版权所有: CGI 编程者之家 程序编制: 山鹰(糊)、 花无缺
本论坛言论纯属发表者个人意见,与 【ChinaJavaWorld.com技术论坛】 立场无关
的用法
忘性真大,一段時間不用,這些簡單的東西又要翻書了,看來,3天不用手生,3天不說口生。的確不假呀。
<html:text>和<html:textarea>标记分别HTML文本框和文本区,属性如下:
属性 描述
Property 定义当表单被提交时送回到服务器的请求参数的名称,或用来确定文本元素当前值的bean的属性名称
Name 属性被查询的bean的名称,它决定了文本框和文本区的值。如果没有设置,将使用与这个内嵌表单相关的ActionForm的名称
<html:text>标记还有以下属性:
属性 描述
Maxlength 能够输入的最大字符数
Size 文本框的大小(字符数)
(补充:这里的字符数是不论是汉字还英文,一个汉字和一个英文字符都算一个字符;与UTF-8对比为:一个汉字3个英文字符;与java中的对比:一个汉字1个英文;与gb2312对比:一个汉字2个英文字符(即2个字节))
例如:<html:text property="articleName" maxlength="50" size="50"/>
parameter的使用(引自项目实施社区以归类并备
转自项目实施社区,在进行系统导航能力提高的编码过程中心得。
request.getParameter()与request.getAttribute()
真是惭愧,我竟然不清楚(也许忘了)它们的区别,又让我在昨天晚上吃了一点亏。后来才注意它们的区别:前者是接受url请求中的字符串参数,后者是接受request中的“属性-值(对象)”的值(对象)。