??xml version="1.0" encoding="utf-8" standalone="yes"?>国产999精品久久,免费黄色在线视频网站,日韩精品久久久免费观看http://www.aygfsteel.com/juhongtao/category/6224.htmlzh-cnFri, 02 Mar 2007 03:30:21 GMTFri, 02 Mar 2007 03:30:21 GMT60在Struts中用JavaBean和ListQ多行数据)cd属?/title><link>http://www.aygfsteel.com/juhongtao/archive/2006/12/14/87619.html</link><dc:creator>javaGrowing</dc:creator><author>javaGrowing</author><pubDate>Thu, 14 Dec 2006 01:28:00 GMT</pubDate><guid>http://www.aygfsteel.com/juhongtao/archive/2006/12/14/87619.html</guid><wfw:comment>http://www.aygfsteel.com/juhongtao/comments/87619.html</wfw:comment><comments>http://www.aygfsteel.com/juhongtao/archive/2006/12/14/87619.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/juhongtao/comments/commentRss/87619.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/juhongtao/services/trackbacks/87619.html</trackback:ping><description><![CDATA[ ?Strust 中,我们可能l常要在 ActionForm 中用其?JavaBean 作ؓ(f)属性类型,q里存在着如何使用好这些属性与 HTML Form 之间的数据交换,下面我们p些问题做一讲解?br /><br />如在用户注册界面中,我们通常?x)将用户的联pL式Ş成一个单独的新的 Class Q如 Contact Q包含以下属性:(x)?sh)?(tel) Q手?cell) Q?Email(email) Q?QQ(qq) Q通信地址 (adress) {等Q这h理也比较清晰Q以下是q个ActionForm 的部分代码:(x)<br /><br />public class RegisterForm extends ActionForm<br /><br />{<br /><br />private Integer id;<br /><br />private String logonName;<br /><br />private String realName;<br /><br />private Contact contact=new Contact();<br /><br />……?.<br /><br />}<br /><br />在这里我们需要将 Contact 实例化(?reset 函数中需要重新实例化Q,q主要因?Struts 的机Ӟ(x)如我们将 HTML 的Form 元素Q如 email Qgl?ActionForm Q?Struts 需要执行的操作是getContact().setEmail(String email) Q如果这时返回的 contact 对象为空的话Q那么赋值如何进行,而且Struts 也不?x)知道如何去实例?Contact Q有时这?JavaBean 的类型有可能是接口,实例化更是未知,所以关于JavaBean cd?ActionForm 中的实例化,你需要自行完成,而且必须完成。至于在实际操作中判?JavaBean是否被进行过相关操作Q不再是初始状态)Q你需要自行判断,其实也很单,如可?Contact cM~写一个函数检验一下即可?br /><br />ActionForm 创徏完毕后,我们需要在 Jsp Form 中引用这?JavaBean cd的属性|那就很简单啦Q只需采用?Form 的属性名U”+?. ”+?JavaBean 中的属性名U”结构构成的名称付给相关元素卛_。如Q?br /><br /><html:text property="contact.email"><br /><br />通过q种方式我们可以处理好 ActionForm 中的 JavaBean cd的属性g?br /><br />实际的情况可能更复杂些,我们有时可能要提交多行数据到后退Q而且行内的数据是相关的,如我们需要提交多个用L(fng)联系方式Q这些行内的数据Q如email Q电(sh)话,手机Q这些数据都是和用户~码相关的,现在我们修改一?Contact c,d一个用L(fng)?(userId)属性,q时我们构徏?ActionForm 中可能需要一个列表数据( List Q类型来处理q种情况。以下是q个 ActionForm的部分代码:(x)<br /><br />public class ModifyBatchContactForm extends ActionForm<br /><br />{<br /><br />private List contact =new AutoArrayList (Contact.class);<br /><br />?.<br /><br />}<br /><br />在以上代码中Q我们同样处理了 List cd数据的初始化?Struts 在给 List 中的对象赋值时Q当焉要先获取 List数据Q然后在获取 List 中某一个对象(通过 IndexQ,最后给对象赋倹{在q里x们可以更详细点分析浏览器端传q来数据Q字D值Ş式如下:(x)contact[0].email= linux_china@hotmail.com Q?Struts 获取 ActionForm 中的 List数据后,通过 Index Q此时ؓ(f) 0 Q来获取 List 中封装的 JavaBean 对象Q然而此?List是空的(管初始化了Q但是没有数据)Q是无法取得装的对象的Q因此我们要?Struts 获取 List中封装的对象的时候给它创Z个,q样׃证对象的获取和赋值的成功q行Q所有我们新Z?AutoArrayList c,l承ArrayList Q只要重?get(int index) Ҏ(gu)卛_Q其实很单,代码如下Q?br /><br />public class AutoArrayList extends ArrayList {<br /><br />private Class itemClass;<br /><br />public AutoArrayList(Class itemClass) {<br /><br />this.itemClass = itemClass;<br /><br />}<br /><br />public Object get(int index) {<br /><br />try {<br /><br />while (index &gt;= size()) {<br /><br />add( itemClass.newInstance());<br /><br />}<br /><br />} catch (Exception e) {<br /><br />e.printStackTrace();<br /><br />}<br /><br />return super.get(index);<br /><br />}<br /><br />}<br /><br />q样我们完成可以多行数据提交的 ActionForm设计Q这里还有点提醒Q如果从览器端传过来的行烦引是跌是的Q如~少中间行,而你不想要这些数据的话,且首行 index相差很大的话Q这U方式可能不太适合。这U多行提交Ş式比较适合对固定行的数据处理。如果行C固定的话Q你可以参考?MapForm 方式实现?br /><br />下面我们q看如何在 Jsp 中用这?ActionForm Q其实只需要执行一个@环即可:(x)<br /><br /><logic:iterate id=" contact " name=" FormName " property=" contact " indexid="index"><br /><br /><html:text name=" contact " property="userId" indexed="true"><br /><br /><html:text name=" contact " property="email" indexed="true"><br /><br /></html:text><br /><br />q里我们再讲解一下,代码中出现的?contact ”(U色Q都?ActionForm 中的 List数据cd变量名称Q请保一_(d)请不要更改名Uͼq也是方便提交到后台的数据接收。?FormName ”ؓ(f)?struts-config中声明的 ActionForm 名称?indexed="true" 可以保生成?html 元素的名U唯一Q不要缺这个声明。以上的Jsp 代码Q你也可以?JSTL 来完成,q你习(fn)惯如何了?br /><br />通过以上步骤Q我们完成了多行数据的提交所有环节,q样 Struts ׃(x)完成其他所有的事情Q我们的代码逻辑和实C单多了?br /><br />ȝQ通过以上两个例子Q相以信?ActionForm 中?JavaBean ?List cd数据不会(x)再陌生,同时使用 MapcdQ这样可创徏更好?ActionForm 设计Q关?MapForm Q请参考http://www.jetmaven.net/documents/j_mapformInStruts.php 。不q引入这U方式后Q在Validator 斚w你可能要q脑筋啦(如通过 XDoclet 生成 Validator文g可能功能不全Q,可能你需要手写一些代码来完成相关工作</html:text></logic:iterate></html:text><img src ="http://www.aygfsteel.com/juhongtao/aggbug/87619.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/juhongtao/" target="_blank">javaGrowing</a> 2006-12-14 09:28 <a href="http://www.aygfsteel.com/juhongtao/archive/2006/12/14/87619.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>扩展Strutshttp://www.aygfsteel.com/juhongtao/archive/2005/12/30/25994.htmljavaGrowingjavaGrowingFri, 30 Dec 2005 01:48:00 GMThttp://www.aygfsteel.com/juhongtao/archive/2005/12/30/25994.htmlhttp://www.aygfsteel.com/juhongtao/comments/25994.htmlhttp://www.aygfsteel.com/juhongtao/archive/2005/12/30/25994.html#Feedback0http://www.aygfsteel.com/juhongtao/comments/commentRss/25994.htmlhttp://www.aygfsteel.com/juhongtao/services/trackbacks/25994.html作者:(x)Sunil Patil
译Q?a target="_new">loryliu


版权声明Q可以Q意{载,转蝲时请务必以超链接形式标明文章原始出处和作者信息及(qing)本声?br>作?
Sunil Patil;loryliu
原文地址:
http://www.onjava.com/pub/a/onjava/2004/11/10/ExtendingStruts.html
中文地址:
http://www.matrix.org.cn/resource/article/43/43857_Struts.html
关键词:(x) extending Struts


?/span>

? 见过许多目开发者实现自׃有的MVC框架。这些开发者ƈ不是因ؓ(f)惛_C同于Struts的某些功能,而是q没有意识到怎么L展Struts。通过 开发自qMVC框架Q你可以掌控全局Q但同时q也意味着你必M出很大的代h(hun)Q在目计划很紧的情况下也许Ҏ(gu)׃可能实现?br>
Struts不但功能强大也易于扩展。你可以通过三种方式来扩展Struts:

1.PlugInQ在应用启动或关闭时L行某业务逻辑Q创Z自己的PlugInc?br>
2.RequestProcessorQ在h处理阶段一个特定点Ʋ执行某业务逻辑Q创Z自己的RequestProcessor。例如:(x)你想l承RequestProcessor来检查用L(fng)录及(qing)在执行每个请求时他是否有权限执行某个动作?br>
3.ActionServletQ在应用启动或关闭或在请求处理阶D|执行某业务逻辑Q承ActionServletcR但是必M只能在PligIn和RequestProcessor都不能满你的需求时候用?br>
本文?x)列举一个简单的Struts应用来示范如何用以上三U方式扩展Struts。在本文末尾资源区有每种方式的可下蝲样例源代码。Struts Validation 框架?Tiles 框架是最成功两个的Struts扩展例子?br>
我是假设读者已l熟(zhn)Struts框架q知道怎样使用它创建简单的应用。如想了解更多有关Struts的资料请参见资源区?br>
PlugIn

Ҏ(gu)Struts文档Q“PlugIn是一个须在应用启动和关闭旉被通知的模块定制资源或服务配置包”。这是_(d)你可以创Z个类Q它实现PlugIn的接口以便在应用启动和关闭时做你惌的事?br>
? 如创Z一个web应用Q其中用Hibernate做ؓ(f)持久化机Ӟ当应用一启动Q就需初始化HinernateQ这样在web应用接收到第一个请? ӞHibernate已被配置完毕q待命。同时在应用关闭时要关闭Hibernate。跟着以下两步可以实现Hibernate PlugIn的需求?br>
1.创徏一个实现PlugIn接口的类Q如下:(x)

public class HibernatePlugIn implements PlugIn{
        private String configFile;
        // This method will be called at application shutdown time
        public void destroy() {
                System.out.println("Entering HibernatePlugIn.destroy()");
                //Put hibernate cleanup code here
                System.out.println("Exiting HibernatePlugIn.destroy()");
        }
        //This method will be called at application startup time
        public void init(ActionServlet actionServlet, ModuleConfig config)
                throws ServletException {
                System.out.println("Entering HibernatePlugIn.init()");
                System.out.println("Value of init parameter " +
                                    getConfigFile());
                System.out.println("Exiting HibernatePlugIn.init()");
        }
        public String getConfigFile() {
                return name;
        }
        public void setConfigFile(String string) {
                configFile = string;
        }
}


实现PlugIn接口的类必须是实C下两个方法:(x)
init() 和destroy().。在应用启动时init()被调用,关闭destroy()被调用。Struts允许你传入初始参数给你的PlugInc;Z? 入参C必须在PlugInc里为每个参数创Z个类似JavaBean形式的setterҎ(gu)。在HibernatePlugInc里Q欲传入 configFile的名字而不是在应用里将它硬~码q去

2.在struts-condig.xml里面加入以下几行告知Strutsq个新的PlugIn

<struts-config>
        ...
        <!-- Message Resources -->
        <message-resources parameter=
          "sample1.resources.ApplicationResources"/>

        <!-- Declare your plugins -->
        <plug-in className="com.sample.util.HibernatePlugIn">
                <set-property property="configFile"
                   value="/hibernate.cfg.xml"/>
        </plug-in>
</struts-config>

ClassName 属性是实现PlugIn接口cȝ全名。ؓ(f)每一个初始化传入PlugIncȝ初始化参数增加一?lt;set-property>元素。在q个例子 里,传入config文档的名Uͼ所以增加了一个config文档路径?lt;set-property>元素?br>
Tiles和Validator框架都是利用PlugInl初始化d配置文g。另外两个你q可以在PlugInc里做的事情是:(x)

假如应用依赖于某配置文gQ那么可以在PlugInc里(g)查其可用性,假如配置文g不可用则抛出ServletException。这导致ActionServlet不可用?br>
PlugIn接口的init()Ҏ(gu)是你改变ModuleConfigҎ(gu)的最后机?x),ModuleConfigҎ(gu)是描q基于Struts模型静态配|信息的集合。一旦PlugIn被处理完毕,Struts׃(x)ModuleCOnfigȝh?br>
h是如何被处理?/span>

ActionServlet 是Struts框架里唯一一个ServletQ它负责处理所有请求。它无论何时收到一个请求,都会(x)首先试着为现有请求找C个子应用。一旦子应用被找刎ͼ 它会(x)为其生成一个RequestProcessor对象Qƈ调用传入HttpServletRequest和HttpServletResponse为参 数的process()Ҏ(gu)?br>
大部分请处理都是在RequestProcessor.process()发生的。Process()Ҏ(gu) 是以模板Ҏ(gu)QTemplate MethodQ的设计模式来实现的Q其中有完成request处理的每个步骤的Ҏ(gu)Q所有这些方法都从process()Ҏ(gu)序调用。例如,L当前? 求的ActionFormcd(g)查当前用h否有权限执行action mapping都有几个单独的方法。这l我们提供了极大的弹性空间。Struts的RequestProcessorҎ(gu)个请求处理步骤都提供了默认的? 现方法。这意味着Q你可以重写你感兴趣的方法,而其余剩下的保留默认实现。例如,Struts默认调用request.isUserInRole()(g)? 用户是否有权限执行当前的ActionMappingQ但如果你需要从数据库中查找Q那么你要做的就是重写processRoles()Ҏ(gu)QƈҎ(gu)用户 角色q回true ?false?br>
首先我们看一下process()Ҏ(gu)的默认实现方式,然后我将解释RequestProcessorc里的每个默认的Ҏ(gu)Q以便你军_要修改请求处理的哪一部分?br>
public void process(HttpServletRequest request,
                        HttpServletResponse response)
    throws IOException, ServletException {
        // Wrap multipart requests with a special wrapper
        request = processMultipart(request);
        // Identify the path component we will
        // use to select a mapping
        String path = processPath(request, response);
        if (path == null) {
            return;
        }
        if (log.isDebugEnabled()) {
            log.debug("Processing a '" + request.getMethod() +
                      "' for path '" + path + "'");
        }
        // Select a Locale for the current user if requested
        processLocale(request, response);
        // Set the content type and no-caching headers
        // if requested
        processContent(request, response);
        processNoCache(request, response);
        // General purpose preprocessing hook
        if (!processPreprocess(request, response)) {
            return;
       }
        // Identify the mapping for this request
        ActionMapping mapping =
            processMapping(request, response, path);
        if (mapping == null) {
            return;
        }
        // Check for any role required to perform this action
        if (!processRoles(request, response, mapping)) {
            return;
        }
        // Process any ActionForm bean related to this request
        ActionForm form =
            processActionForm(request, response, mapping);
        processPopulate(request, response, form, mapping);
        if (!processValidate(request, response, form, mapping)) {
            return;
        }
        // Process a forward or include specified by this mapping
        if (!processForward(request, response, mapping)) {
            return;
        }
        if (!processInclude(request, response, mapping)) {
            return;
        }
        // Create or acquire the Action instance to
        // process this request
        Action action =
            processActionCreate(request, response, mapping);
        if (action == null) {
            return;
        }
        // Call the Action instance itself
        ActionForward forward =
            processActionPerform(request, response,
                                action, form, mapping);
        // Process the returned ActionForward instance
        processForwardConfig(request, response, forward);
    }



1、processMultipart(): ? q个Ҏ(gu)中,Strutsdrequest以找出contentType是否为multipart/form-data。假如是Q则解析q将其打包成一 个实现HttpServletRequest的包。当你成生一个放|数据的HTML FORMӞrequest的contentType默认是application/x-www-form-urlencoded。但是如果你的form 的inputcd是FILE-type允许用户上蝲文gQ那么你必须把form的contentType改ؓ(f)multipart/form-data。如 q样做,你永q不能通过HttpServletRequest的getParameter()来读取用h交的form|你必M InputStream的Ş式读取requestQ然后解析它得到倹{?br>
2、processPath(): 在这个方法中QStruts读取request的URI以判断用来得到ActionMapping元素的\径?br>
3、processLocale(): 在这个方法中QStruts得到当前request的LocaleQLocale假如被配|,作? org.apache.struts.action.LOCALE属性的D存入HttpSession。这个方法的附作用是HttpSession?x)? 创徏。假如你不想此事发生Q可在struts-config.xml 文g里ControllerConfig的local属性设|ؓ(f)false,如下Q?br>
<controller>
        <set-property property="locale" value="false"/>
</controller>


4、processContent()Q?/b>通过调用response.setContentType()讄response的contentType。这个方法首先会(x)试着的得到配|在struts-config.xml里的contentType。默认ؓ(f)text/htmlQ重写方法如下:(x)
<controller>
        <set-property property="contentType" value="text/plain"/>
</controller>


5、processNoCache()Q?/b>Strutsؓ(f)每个response的设|以下三个headerQ假如已在struts 的config.xml配|ؓ(f)no-cache?br>
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 1);


假如你想讄为no-cache headerQ在struts-config.xml中加如以下几?br>
<controller>
        <set-property property="noCache" value="true"/>
</controller>


6、processPreprocess()Q?/b>q是一个一般意义的预处理hookQ其可被子类重写。在RequestProcessor里的实现什么都没有做,Lq回true。如此方法返回false?x)中断请求处理?br>
7、processMapping():q个Ҏ(gu)?x)利用path信息扑ֈActionMapping对象。ActionMapping对象在struts-config.xml file文g里表CZؓ(f)<action>
<action path="/newcontact" type="com.sample.NewContactAction"
        name="newContactForm" scope="request">
        <forward name="sucess" path="/sucessPage.do"/>
        <forward name="failure" path="/failurePage.do"/>
</action>


ActionMapping元素包含了如Actioncȝ名称?qing)在h中用到的ActionForm的信息,另外q有配置在当前ActionMapping的里的ActionForwards信息?br>
8、processRoles(): Struts的web 应用安全提供了一个认证机制。这是_(d)一旦用L(fng)录到容器QStruts的processRoles()Ҏ(gu)通过调用request.isUserInRole()可以(g)查他是否有权限执行给定的ActionMapping?br>        <action path="/addUser" roles="administrator"/>

假如你有一个AddUserActionQ限制只有administrator权限的用h能新d用户。你所要做的就是在AddUserAction 的action元素里添加一个gؓ(f)administrator的role属性?br>
9、processActionForm()Q?/b>每个ActionMapping都有一个与它关联的ActionFormcRstruts在处理ActionMappingӞ他会(x)?lt;action>里name属性找到相关的ActionFormcȝ倹{?br>
<form-bean name="newContactForm" 
           type="org.apache.struts.action.DynaActionForm">
                <form-property name="firstName"
                          type="java.lang.String"/>
                <form-property name="lastName"
                          type="java.lang.String"/>
</form-bean>


在这个例子里Q首先会(x)(g)查org.apache.struts.action.DynaActionFormcȝ对象是否在request 范围内。如是,则用它Q否则创Z个新的对象ƈ在request范围内设|它?br>
10、processPopulate():Q?/b>在这个方法里QStruts匹配的request parameters值填入ActionFormcȝ实例变量中?br>
11、processValidate()Q?/b>Struts调用ActionForm的validate()Ҏ(gu)。假如validate()q回ActionErrorsQStruts用戯{到由<action>里的input属性标C的面?br>
12、processForward() and processInclude()Q?/b>在这两个Ҏ(gu)里,Struts(g)?lt;action>元素的forward和include属性的|假如有配|,则把forward和include h攑֜配置的页面内?br>
<action forward="/Login.jsp" path="/loginInput"/>
        <action include="/Login.jsp" path="/loginInput"/>


? 可以从他们的名字看出其不同之处。processForward()调用RequestDispatcher.forward(),Q? processInclude()调用RequestDispatcher.include()。假如你同时配置了orward 和include 属性,StrutsM(x)调用forwardQ因为forward,是首先被处理的?br>
13、processActionCreate()Q?/b>q个Ҏ(gu)?lt;action>的type属性得到ActioncdQƈ创徏q回它的实例。在q里例子中struts创Z个com.sample.NewContactActioncȝ实例?br>
14、processActionPerform()Q?/b>q个Ҏ(gu)调用Action cȝexecute()Ҏ(gu)Q其中有你写入的业务逻辑?br>
15、processForwardConfig()Q?/b>Actioncȝexecute()会(x)q回一个ActionForwardcd的对象,指出哪一面展C给用户。因此Strutsؓ(f)q个面创徏RequestDispatchetQ然后再调用RequestDispatcher.forward()Ҏ(gu)?br>
? 上列出的Ҏ(gu)解释了RequestProcessor在请求处理的每步默认实现?qing)各个步骤执行的序。正如你所见,RequestProcessor很有 Ҏ(gu),它允怽通过讄<controller>里的属性来配置它。例如,假如你的应用生成XML内容而不是HTMLQ你可以通过讄 controller的某个属性来通知Struts?br>
创徏你自qRequestProcessor

? 以上内容我们已经明白了RequestProcessor的默认实现是怎样工作的,现在我将通过创徏你自qRequestProcessor.展示一? 怎样自定义RequestProcessor的例子。ؓ(f)了演C创Z个自定义RequestProcessorQ我修改例子实C下连个业务需求:(x)

我们要创Z个ContactImageActionc,它将生成images而不是一般的HTMl面

在处理这个请求之前,通过(g)查session里的userName属性来认用户是否d。假如此属性没有被扑ֈQ则用戯{到登录页面?br>

分两步来实现以上q个业务需求?br>创徏你自qCustomRequestProcessorc,它将l承RequestProcessorc,如下Q?br>
public class CustomRequestProcessor
    extends RequestProcessor {
        protected boolean processPreprocess (
            HttpServletRequest request,
            HttpServletResponse response) {
            HttpSession session = request.getSession(false);
        //If user is trying to access login page
        // then don't check
        if( request.getServletPath().equals("/loginInput.do")
            || request.getServletPath().equals("/login.do") )
            return true;
        //Check if userName attribute is there is session.
        //If so, it means user has allready logged in
        if( session != null &&
        session.getAttribute("userName") != null)
            return true;
        else{
            try{
                //If no redirect user to login Page
                request.getRequestDispatcher
                    ("/Login.jsp").forward(request,response);
            }catch(Exception ex){
            }
        }
        return false;
    }

    protected void processContent(HttpServletRequest request,
                HttpServletResponse response) {
            //Check if user is requesting ContactImageAction
            // if yes then set image/gif as content type
            if( request.getServletPath().equals("/contactimage.do")){
                response.setContentType("image/gif");
                return;
            }
        super.processContent(request, response);
    }
}


在CustomRequestProcessor cȝprocessPreprocessҎ(gu)里,(g)查session的userName属性,假如没有扑ֈQ将用户转到d面?br>
? 于生images作ؓ(f)ContactImageActioncȝ输出Q必要重写processContentҎ(gu)。首先检查其request是否h /contactimage路径Q如是则讄contentType为image/gifQ否则ؓ(f)text/html?br>
加入以下几行代码到sruts-config.xml文g里的<action-mapping>后面Q告知Struts QCustomRequestProcessor应该被用作RequestProcessorc?br>
<controller>
        <set-property  property="processorClass"
        value="com.sample.util.CustomRequestProcessor"/>
</controller>


? 注意Q假如你只是很少生成contentType不是text/html输出的Actionc,重写processContent()没有问题。如不是 q种情况Q你必须创徏一个Struts子系l来处理生成image  Action的请求ƈ讄contentType为image/gif

Title框架使用自己的RequestProcessor来装饰Struts生成的输出?br>
ActionServlet

假如你仔l研IStruts web应用的web.xml文gQ它看上dq样Q?br>
<web-app >
        <servlet>
            <servlet-name>action=</servlet-name>
            <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
            <!-- All your init-params go here-->
        </servlet>
        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
</web-app >


q? 是_(d)ActionServlet负责处理所有发向Struts的请求。你可以创徏ActionServlet的一个子c,假如你想在应用启动和关闭? 或每ơ请求时做某些事情。但是你必须在承ActionServletcd创徏PlugIn ?RequestProcessor。在Servlet 1.1前,Title框架是基于承ActionServletcL装饰一个生成的response。但?.1开始,׃? TilesRequestProcessorcR?br>
l论

开发你自己的MVC模型是一个很大的军_——你必须考虑开发和l护代码的时间和资源。Struts是一个功能强大且E_的框Ӟ你可以修改它以其满你大部分的业务需求?br>
另一斚wQ也不要L地决定扩展Struts。假如你在RequestProcessor里放入一些低效率的代码,q些代码在每次h时执行ƈ大大地降低整个应用的效率。当然L创徏你自qMVC框架比扩展Struts更好的情c(din)?br>
资源
下蝲本文源码Q[下蝲文g]
Struts主页
"Jakarta Struts框架介绍"
"学习(fn)Jakarta Struts 1.1"


Sunil Pail已从事J2EE四年Q现今与IBM实验室合作?img src ="http://www.aygfsteel.com/juhongtao/aggbug/25994.html" width = "1" height = "1" />

javaGrowing 2005-12-30 09:48 发表评论
]]>
struts中文的解?/title><link>http://www.aygfsteel.com/juhongtao/archive/2005/12/27/25587.html</link><dc:creator>javaGrowing</dc:creator><author>javaGrowing</author><pubDate>Tue, 27 Dec 2005 07:56:00 GMT</pubDate><guid>http://www.aygfsteel.com/juhongtao/archive/2005/12/27/25587.html</guid><wfw:comment>http://www.aygfsteel.com/juhongtao/comments/25587.html</wfw:comment><comments>http://www.aygfsteel.com/juhongtao/archive/2005/12/27/25587.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/juhongtao/comments/commentRss/25587.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/juhongtao/services/trackbacks/25587.html</trackback:ping><description><![CDATA[<span id="wmqeeuq" class="javascript" id="text9057"> 转自 <a target="_blank" class="ilink">www.javaresearch.org</a><br>作?fishandfly <br><br>1.?font style="background-color: rgb(255, 255, 0);"><b>ApplicationResources.properties</b></font>支持中文<br>建立一个ApplicationResources_ISO.properties文gQ把应用E序用的message都写q去Q然后在dos下执行这个命令,<br>native2ascii -encoding gb2312 ApplicationResources_ISO.properties <font style="background-color: rgb(255, 255, 0);"><b>ApplicationResources.properties</b></font><br>q样׃(x)ISO~码的ApplicationResources转换成GB2312~码的格式了Q同时保存到<font style="background-color: rgb(255, 255, 0);"><b>ApplicationResources.properties</b></font>.<br>native2asciiq个工具是jdk自带的一个东东,所以如果path都设定正就可以直接q行了,你可以在$java_home$/bin下找C?br>转换后的中文cM于这个样?br>iso 格式?Qtj.type=商品车类?br>gb2312格式?Qtj.type=\u5546\u54c1\u8f66\u7c7b\u578b<br>然后在struts-config.xml中设|应用这个资源文?br><message-resources parameter="com.huahang.tj.ApplicationResources" key="org.apache.struts.action.MESSAGE" /><br>开发jsp时在jsp的开头写?lt;%@ page contentType="text/html; charset=gb2312" %>Q将字符集设|成gb2312可以了?br><br>2.使数据库操作支持中文?br>数据库操作支持中文一直让我比较头痛,但是感谢善解向我推荐了www.chinaxp.orgQ这个网站是用struts框架开发的Q而且<br>开放源码,下蝲了源码后发现它的中文处理得很好,阅读部分源码Q没有发C么特D的字符集{换,很纳P偶然看到g|友<br>留言知道原来servlet可以l一讄字符转换。chinaxp.org是q么做的?br>在web.xml中加?br><filter><br><filter-name>Set Character Encoding</filter-name><br><filter-class>com.huahang.tj.struts.filters.SetCharacterEncodingFilter</filter-class><br><init-param><br><param-name>encoding</param-name><br><param-value>GB2312</param-value><br></init-param><br><init-param><br><param-name>ignore</param-name><br><param-value>true</param-value><br></init-param><br></filter><br><filter-mapping><br><filter-name>Set Character Encoding</filter-name><br><servlet-name>action</servlet-name><br></filter-mapping><br>q里?x)涉及(qing)一个bean,源码如下Q?br>/*<br>* XP Forum<br>* <br>* Copyright <img src="http://www.cjsdn.net/images/smiles/coffee_smile.gif" alt="Coffee" width="19"> 2002-2003 RedSoft Group. All rights reserved.<br>*<br>*/<br>package com.huahang.tj.struts.filters;<br><br>import javax.servlet.*;<br>import java.io.IOException;<br><br>/**<br>* <p>Filter that sets the character encoding to be used in parsing the<br>* incoming request, either unconditionally or only if the client did not<br>* specify a character encoding. Configuration of this filter is based on<br>* the following initialization parameters:</p><br>* <ul><br>* <li><strong>encoding</strong> - The character encoding to be configured<br>* for this request, either conditionally or unconditionally based on<br>* the <code>ignore</code> initialization parameter. This parameter<br>* is required, so there is no default.</li><br>* <li><strong>ignore</strong> - If set to "true", any character encoding<br>* specified by the client is ignored, and the value returned by the<br>* <code>selectEncoding()</code> method is set. If set to "false,<br>* <code>selectEncoding()</code> is called <strong>only</strong> if the<br>* client has not already specified an encoding. By default, this<br>* parameter is set to "true".</li><br>* </ul><br>*<br>* <p>Although this filter can be used unchanged, it is also easy to<br>* subclass it and make the <code>selectEncoding()</code> method more<br>* intelligent about what encoding to choose, based on characteristics of<br>* the incoming request (such as the values of the <code>Accept-Language</code><br>* and <code>User-Agent</code> headers, or a value stashed in the current<br>* user's session.</p><br>*<br>* @author <a href="mailto:jwtronics@yahoo.com">John Wong</a><br>*<br>* @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002/04/10 13:59:27 johnwong Exp $<br>*/<br>public class SetCharacterEncodingFilter implements Filter {<br><br>// ----------------------------------------------------- Instance Variables<br><br>/**<br>* The default character encoding to set for requests that pass through<br>* this filter.<br>*/<br>protected String encoding = null;<br><br>/**<br>* The filter configuration object we are associated with. If this value<br>* is null, this filter instance is not currently configured.<br>*/<br>protected FilterConfig filterConfig = null;<br><br>/**<br>* Should a character encoding specified by the client be ignored?<br>*/<br>protected boolean ignore = true;<br><br>// --------------------------------------------------------- Public Methods<br><br>/**<br>* Take this filter out of service.<br>*/<br>public void destroy() {<br><br>this.encoding = null;<br>this.filterConfig = null;<br><br>}<br><br>/**<br>* Select and set (if specified) the character encoding to be used to<br>* interpret request parameters for this request.<br>*<br>* @param request The servlet request we are processing<br>* @param result The servlet response we are creating<br>* @param chain The filter chain we are processing<br>*<br>* @exception IOException if an input/output error occurs<br>* @exception ServletException if a servlet error occurs<br>*/<br>public void doFilter(ServletRequest request, ServletResponse response,<br>FilterChain chain)<br>throws IOException, ServletException {<br><br>// Conditionally select and set the character encoding to be used<br>if (ignore || (request.getCharacterEncoding() == null)) {<br>String encoding = selectEncoding(request);<br>if (encoding != null)<br>request.setCharacterEncoding(encoding);<br>}<br><br>// Pass control on to the next filter<br>chain.doFilter(request, response);<br><br>}<br><br>/**<br>* Place this filter into service.<br>*<br>* @param filterConfig The filter configuration object<br>*/<br>public void init(FilterConfig filterConfig) throws ServletException {<br><br>this.filterConfig = filterConfig;<br>this.encoding = filterConfig.getInitParameter("encoding");<br>String value = filterConfig.getInitParameter("ignore");<br>if (value == null)<br>this.ignore = true;<br>else if (value.equalsIgnoreCase("true"))<br>this.ignore = true;<br>else if (value.equalsIgnoreCase("yes"))<br>this.ignore = true;<br>else<br>this.ignore = false;<br><br>}<br><br>// ------------------------------------------------------ Protected Methods<br><br>/**<br>* Select an appropriate character encoding to be used, based on the<br>* characteristics of the current request and/or filter initialization<br>* parameters. If no character encoding should be set, return<br>* <code>null</code>.<br>* <p><br>* The default implementation unconditionally returns the value configured<br>* by the <strong>encoding</strong> initialization parameter for this<br>* filter.<br>*<br>* @param request The servlet request we are processing<br>*/<br>protected String selectEncoding(ServletRequest request) {<br><br>return (this.encoding);<br><br>}<br><br>}//EOC<br>加上q个后,在action中就可以直接从form中接收gb2312~码的数据了Q返回时自然也是gb2312了?br>但是q个好像需要servlet 2.2以上的容?br><br>l合上面的方法,我解决了struts中的中文问题Q现在还没发现新的问题?br><br>我的环境?br>windows2000 Professional,tomcat 4.04 , struts1.1b2 </span> <br><img src ="http://www.aygfsteel.com/juhongtao/aggbug/25587.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/juhongtao/" target="_blank">javaGrowing</a> 2005-12-27 15:56 <a href="http://www.aygfsteel.com/juhongtao/archive/2005/12/27/25587.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">̩</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ȫ</a>| <a href="http://" target="_blank">᰸</a>| <a href="http://" target="_blank">Ȫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">â</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">DZɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˹</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɳƺ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ȫ</a>| <a href="http://" target="_blank">˼</a>| <a href="http://" target="_blank">ν</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͼľ</a>| <a href="http://" target="_blank">Դ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƴ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͬ</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>