亚洲高清无在码在线无弹窗 ,亚洲成人福利在线观看,亚洲国产天堂久久综合网站http://m.tkk7.com/usherlight/category/28648.html天平山上白云泉,云自無(wú)心水自閑。何必奔沖山下去,更添波浪向人間!zh-cnThu, 19 Nov 2009 06:35:30 GMTThu, 19 Nov 2009 06:35:30 GMT60解決struts2上傳文件大小限制的方法http://m.tkk7.com/usherlight/archive/2009/11/19/302910.html云自無(wú)心水自閑云自無(wú)心水自閑Thu, 19 Nov 2009 05:44:00 GMThttp://m.tkk7.com/usherlight/archive/2009/11/19/302910.htmlhttp://m.tkk7.com/usherlight/comments/302910.htmlhttp://m.tkk7.com/usherlight/archive/2009/11/19/302910.html#Feedback0http://m.tkk7.com/usherlight/comments/commentRss/302910.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/302910.html
<interceptor-ref name="fileUpload">
        <param name="maximumSize">1000000</param>
        <param name="allowedTypes">image/gif,image/jpeg,image/jpg,image/png</param>
</interceptor-ref>

但是我設(shè)置了之后并沒(méi)有作用。
后來(lái),仔細(xì)查看日志后才發(fā)現(xiàn)錯(cuò)誤是commons-fileupload里面的文件大小限制引起了錯(cuò)誤。
在struts.xml中,添加
<constant name="struts.multipart.maxSize" value="16777216"/>
解決問(wèn)題!



云自無(wú)心水自閑 2009-11-19 13:44 發(fā)表評(píng)論
]]>
Extjs Tree + JSON + Struts2 的所有示例源代碼和war文件下載http://m.tkk7.com/usherlight/archive/2009/09/01/293417.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 01 Sep 2009 03:07:00 GMThttp://m.tkk7.com/usherlight/archive/2009/09/01/293417.htmlhttp://m.tkk7.com/usherlight/comments/293417.htmlhttp://m.tkk7.com/usherlight/archive/2009/09/01/293417.html#Feedback5http://m.tkk7.com/usherlight/comments/commentRss/293417.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/293417.htmlExtjs Tree + JSON + Struts2中我介紹了如何異步加載一個(gè)Extjs的樹(shù),但是很多網(wǎng)友留言說(shuō)不能成功操作。現(xiàn)在我自己做了一個(gè)所有源代碼的包,供大家下載。
有幾點(diǎn)事項(xiàng)請(qǐng)大家注意
1、blogjava的文件上載要求單個(gè)文件不能超過(guò)4M,所以,我把web-inf目錄下的所有jar文件刪除了。
所有jar文件的列表是:
commons-beanutils-1.7.0.jar
commons-collections-3.2.jar
commons-digester-1.6.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
ezmorph-1.0.4.jar
freemarker-2.3.8.jar
javassist-3.8.1.jar
json-lib-2.2.1-jdk15.jar
log4j-1.2.13.jar
ognl-2.6.11.jar
struts2-core-2.0.11.jar
xml-apis-1.0.b2.jar
xwork-2.0.4.jar
注意紅色標(biāo)記的那個(gè)jar文件是上次隨筆中遺漏了的。這個(gè)文件是需要的。
2、blogjava要求上傳文件不能是war文件,所以我把war文件改成了rar后綴。
文件的URL: war文件下載



云自無(wú)心水自閑 2009-09-01 11:07 發(fā)表評(píng)論
]]>
struts2中的conventions插件http://m.tkk7.com/usherlight/archive/2009/08/24/292372.html云自無(wú)心水自閑云自無(wú)心水自閑Mon, 24 Aug 2009 06:25:00 GMThttp://m.tkk7.com/usherlight/archive/2009/08/24/292372.htmlhttp://m.tkk7.com/usherlight/comments/292372.htmlhttp://m.tkk7.com/usherlight/archive/2009/08/24/292372.html#Feedback0http://m.tkk7.com/usherlight/comments/commentRss/292372.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/292372.html 假設(shè)有一個(gè)類:com.example.actions.HelloWorld,
Struts2會(huì)自動(dòng)搜索所有實(shí)現(xiàn)了com.opensymphony.xwork2.Action接口或者在struts.xml中<constant name="struts.convention.package.locators" value="actions"/> 指定的包下的類。
現(xiàn)存HelloWorld只是一個(gè)POJO,但是他在actions包下,這樣Struts2就認(rèn)可這是一個(gè)Action.
那么URL會(huì)是什么呢?是hello-world,類似于:http://localhost:8080/<contextPath>/hello-world.action.
如果你不喜歡這樣的自動(dòng)分配的URL,那么可以在里面的方法使用@Action來(lái)改變
@Action("/helloWorld")
public void execute() throws Exception {
    return "success";
}

云自無(wú)心水自閑 2009-08-24 14:25 發(fā)表評(píng)論
]]>
Struts2中ZeroConfig和CodeBehind下的Stream類型返回http://m.tkk7.com/usherlight/archive/2009/01/06/250149.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 06 Jan 2009 09:30:00 GMThttp://m.tkk7.com/usherlight/archive/2009/01/06/250149.htmlhttp://m.tkk7.com/usherlight/comments/250149.htmlhttp://m.tkk7.com/usherlight/archive/2009/01/06/250149.html#Feedback0http://m.tkk7.com/usherlight/comments/commentRss/250149.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/250149.html 

Struts2的官方文檔看似琳瑯滿目,但實(shí)際上并不完備,許多細(xì)節(jié)問(wèn)題并沒(méi)有深入涉及,部分內(nèi)容甚至還有錯(cuò)誤(可參見(jiàn):http://m.tkk7.com/usherlight/archive/2008/12/30/249143.html)。這次主要是補(bǔ)充一下,使用了ZeroConfig插件情況下,如何返回Stream類型的配置。
在ZeroConfig+CodeBehind結(jié)合使用的情況下,Struts.xml中基本上已經(jīng)空無(wú)一物了。配置基本上使用Annotation在Java的類中注釋完成。

@Parent("default")
@Result(name="rawFile", value="inputStream", type=StreamResult.class, params={"contentType", "text/html", "inputName", "inputStream", "", "", "bufferSize", "1024"})
public class FileDownloadAction {
        public String execute() throws Exception {
                inputStream = new FileInputStream("c:\\temp\\file.txt");               
        }
        private InputStream inputStream;

        //... getter and setter
}
這里最重要的是Result里面params的寫法,params后面的大括號(hào)中,奇數(shù)個(gè)字符串是key值,偶數(shù)個(gè)字符串是value值。
其中,inputName的值-inputStream要和Class中的InputStream的屬性名一致,而Result中的value的值也要與之一致。



云自無(wú)心水自閑 2009-01-06 17:30 發(fā)表評(píng)論
]]>
Struts2文檔中一個(gè)錯(cuò)誤http://m.tkk7.com/usherlight/archive/2008/12/30/249143.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 30 Dec 2008 05:17:00 GMThttp://m.tkk7.com/usherlight/archive/2008/12/30/249143.htmlhttp://m.tkk7.com/usherlight/comments/249143.htmlhttp://m.tkk7.com/usherlight/archive/2008/12/30/249143.html#Feedback3http://m.tkk7.com/usherlight/comments/commentRss/249143.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/249143.html 具體內(nèi)容就是下面這一部分:
<s:url id="testUrlId" namespace="/subscriber" action="customField" method="delete">
<s:param name="customFieldDefinition.id" value="${id}"/>
</s:url>
經(jīng)過(guò)嘗試發(fā)現(xiàn)實(shí)際上應(yīng)該這樣寫: <s:param name="customFieldDefinition.id" value="id"/>
struts2的文檔一直被大家所指責(zé),看來(lái)這種指責(zé)不無(wú)道理啊

云自無(wú)心水自閑 2008-12-30 13:17 發(fā)表評(píng)論
]]>
FreeMarker中通過(guò)Struts2標(biāo)簽直接調(diào)用Java類獲得結(jié)果值http://m.tkk7.com/usherlight/archive/2008/11/21/241781.html云自無(wú)心水自閑云自無(wú)心水自閑Thu, 20 Nov 2008 23:59:00 GMThttp://m.tkk7.com/usherlight/archive/2008/11/21/241781.htmlhttp://m.tkk7.com/usherlight/comments/241781.htmlhttp://m.tkk7.com/usherlight/archive/2008/11/21/241781.html#Feedback0http://m.tkk7.com/usherlight/comments/commentRss/241781.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/241781.html <@s.set name="val" value="@com.test.utils.Property@getInstance().get('Value')"/>

然后就可以使用以下的語(yǔ)句在FreeMarker中取得val的值
<#if (Request.appType)?default("") == "OK">
</#if>



云自無(wú)心水自閑 2008-11-21 07:59 發(fā)表評(píng)論
]]>
Struts2性能問(wèn)題的最終解決方法http://m.tkk7.com/usherlight/archive/2008/09/02/226501.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 02 Sep 2008 13:02:00 GMThttp://m.tkk7.com/usherlight/archive/2008/09/02/226501.htmlhttp://m.tkk7.com/usherlight/comments/226501.htmlhttp://m.tkk7.com/usherlight/archive/2008/09/02/226501.html#Feedback5http://m.tkk7.com/usherlight/comments/commentRss/226501.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/226501.html通過(guò)上兩篇文章的研究,
詳見(jiàn):
我的struts2項(xiàng)目性能調(diào)優(yōu)三步曲:http://m.tkk7.com/usherlight/archive/2008/07/01/211869.html
我的struts2項(xiàng)目性能調(diào)優(yōu)三步曲(續(xù)):http://m.tkk7.com/usherlight/archive/2008/07/12/214462.html
得出的結(jié)論是:影響Struts2性能的原因在于Ognl的Value Stack的性能不佳。那么如果解決呢:


* 我首先嘗試使用JSF。
一開(kāi)始選擇JSF的原因主要是:
1、Stuts2自己提供了JSF的Plugin
2、JSF是Sun作為標(biāo)準(zhǔn)提出,而且已經(jīng)通過(guò)的。從Google的趨勢(shì)搜索上也可以看出,搜索JSF的人在增多。
3、JSF作為一種以組件為基礎(chǔ)的Web Framework有其獨(dú)到之處,其內(nèi)建的和其他許多開(kāi)源的組件使用起來(lái)相當(dāng)方便、強(qiáng)大。當(dāng)然,對(duì)于不同的應(yīng)用來(lái)說(shuō)也有不利之處(后面會(huì)提到),但是如果能夠堅(jiān)持長(zhǎng)期使用,逐漸積累組件庫(kù)的話,JSF是一個(gè)很好的選擇。
4、JSF的文檔(或者說(shuō)是書籍)還是比較多的。


經(jīng)過(guò)測(cè)試使用后,發(fā)現(xiàn)其性能與Struts2相比確實(shí)提升不少。但是后來(lái)遇到了一個(gè)問(wèn)題,所以最后還是放棄了JSF。這個(gè)問(wèn)題是關(guān)于JSF的DataTable的,JSF提供的DataTable其實(shí)使用起來(lái)很方便,可定制化程度也不錯(cuò),只是剛好缺少了我所希望的功能(也可能是我不知道如何實(shí)現(xiàn))。我的應(yīng)用中的DataTable是一個(gè)動(dòng)態(tài)的結(jié)果集,也就是說(shuō)輸出的列是不能預(yù)先確定的,而DataTable卻要求先聲明好所有的DataColumn,我不知道如何解決這個(gè)問(wèn)題。所以最后放棄了JSF。


* 我的第二個(gè)選擇是FreeMarker
選擇FreeMarker的原因是:
1、FreeMarker是Struts2缺少的模板引擎,Struts2的標(biāo)簽大部分是使用FreeMarker的,使用FreeMarker的話,連Plugin都省去了。
2、FreeMarker相對(duì)比較輕量級(jí)、因?yàn)樗旧碇皇且粋€(gè)模板引擎,與JSF這樣一個(gè)大而全的WebFramework相對(duì),輕巧多了。
3、FreeMarker的學(xué)習(xí)起來(lái)非常容易,只要把他網(wǎng)站上的Document過(guò)一遍,基本上就OK了。
4、FreeMarker雖然體積小,功能還是相當(dāng)強(qiáng)的,I18N,Converter之類的東西基本都全了,至少我所需要的功能全有。
5、FreeMarker相當(dāng)靈活,他不象JSF把底層的東西封裝了以后,暴露出一些屬性可以設(shè)置,如果你需要的屬性不能設(shè)置,你就沒(méi)有辦法了。在FreeMarker你直接操作最底層的東西,擁有很大的靈活性。當(dāng)然,犧牲了一些方便性,比如,要用FreeMarker生成一個(gè)下拉框,就需要較多的工作量了。


測(cè)試之后,使用FreeMarker的性能很不錯(cuò),在大數(shù)據(jù)量操作的情況下,至少一個(gè)數(shù)量級(jí)的性能提升。

主要原因是freeMarker的值直接從action中取得的,所以避開(kāi)了ognl的stack value.


* 我的最終結(jié)論,如果要在Struts2中,展示或者操作大量數(shù)據(jù),強(qiáng)烈推薦使用FreeMarker。




云自無(wú)心水自閑 2008-09-02 21:02 發(fā)表評(píng)論
]]>
struts2 結(jié)合 dhtmlx treehttp://m.tkk7.com/usherlight/archive/2008/08/07/220756.html云自無(wú)心水自閑云自無(wú)心水自閑Thu, 07 Aug 2008 12:16:00 GMThttp://m.tkk7.com/usherlight/archive/2008/08/07/220756.htmlhttp://m.tkk7.com/usherlight/comments/220756.htmlhttp://m.tkk7.com/usherlight/archive/2008/08/07/220756.html#Feedback2http://m.tkk7.com/usherlight/comments/commentRss/220756.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/220756.htmlhttp://dhtmlx.com
現(xiàn)在把Struts2結(jié)合DHtmlxTree的經(jīng)驗(yàn)心得整理一下,發(fā)表出來(lái):
一、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>

    <package name="demo" extends="struts-default">
        <action name="menu" method="execute" class="demo.TreeMenuAction">
                <result>/WEB-INF/menu.jsp</result>
        </action>
    </package>
</struts>


二、tree.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String 
path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%
>
 
<html>
 
<head>
 
<title>Main Page</title>
 
<!-- 注意此處的路徑需要根據(jù)各自具體情況修改 --> 
<link rel="STYLESHEET" type="text/css" href="styles/dhtmlxtree.css">
<script src="scripts/dhtmlxcommon.js"></script> 
<script src="scripts/dhtmlxtree.js"></script>
 
</head>
 
<body onload="loadTree(); " style="padding: 0; margin: 0; overflow: hidden; height: 100%;">
 
 
<script>
String.prototype._dhx_trim = function(){
    return this.replace(/
&nbsp;/g," ").replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"");
}
 
 
/* init tree */
 var tree;
  
function loadTree(){
    tree=new dhtmlXTreeObject("doctree_box","100%","100%",0);
    tree.setImagePath("images/");    
<!-- 注意此處的路徑需要根據(jù)各自具體情況修改 --> 
    tree.setOnClickHandler(
        function(id){ openPathDocs(id); }
    );
    tree.loadXML("
<%=basePath%>/menu.do"); 
 }
 
/* open path funtion */

function openPathDocs(id){
    if (tree.getUserData(id, "thisurl") != null ){
        window.frames.sampleframe.location.href = "
<%=path%>/" + tree.getUserData(id, "thisurl") + ".do";
        return;
    }
}
 
function autoselectNode(){
    tree.selectItem(node,true);
    tree.openItem(node);

 
</script>
 
 
 
 
<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0">
    
<tr>
        
<td valign="top" width="276">
            
<div id="doctree_box" style="width: 274px; height: 100%;"></div>
        
</td>
        
<td width="10" background="images/grid.gif">
            
&nbsp;
        
</td>
        
<td align="right"> 
            
<iframe id="sampleframe" name="sampleframe" width="100%" height="99%" frameborder="0" src="blank.html" style="border: 0px solid #cecece;"></iframe>
        
</td>
    
</tr>
</table>
 
 
</body>
</html>
 

上面的JavaScript基本上是從dhtmlx的例子中修改而來(lái),理解起來(lái)并不復(fù)雜,只有
String.prototype._dhx_trim = function(){
 return this.replace(/&nbsp;/g," ").replace(/(^[ \t\n\r]*)|([ \t\n\r]*$)/g,"");
}
這一段代碼含義不明。


三、Action

package demo;
 
public class TreeMenuAction {
 
    
private String menuString;
 
    
public String execute() {
        StringBuffer buf 
= new StringBuffer();
        buf.append(
"<tree id=\"0\">");
        buf.append(
" <item text=\"Java\">");
        buf.append(
" <item text=\"Thinking in java\">");
        buf.append(
" <userdata name=\"thisurl\">java_tij.do</userdata>");
        buf.append(
" </item>");
        buf.append(
" <item text=\"Head first design pattern\">");
        buf.append(
" <userdata name=\"thisurl\">java_hfdp.do</userdata>");
        buf.append(
" </item>");
        buf.append(
" </item>");
        buf.append(
" <item text=\"Fiction\">");
        buf.append(
" <item text=\"Harry Porter\">");
        buf.append(
" <userdata name=\"thisurl\">fiction_hp.do</userdata>");
        buf.append(
" </item>");
        buf.append(
" <item text=\"Oliver Twist\">");
        buf.append(
" <userdata name=\"thisurl\">fiction_ot.do</userdata>");
        buf.append(
" </item>");
        buf.append(
" </item>");
        buf.append(
"</tree>");
         
        menuString 
= buf.toString();
         
        
return "success";
    }

     
     
    
public String getMenuString() {
        
return menuString;
    }

     
     
    
public void setMenuString(String menuString) {
        
this.menuString = menuString;
    }

}

 

 
四、menu.jsp
 

<%@ page contentType="text/xml;charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>

<s:property value="menuXmlString" escape="false"/>


過(guò)程是這樣的:首先在瀏覽器地址欄中輸入:http://......./tree.jsp
展示tree.jsp,在load函數(shù)中調(diào)用menu.do

menu.do對(duì)應(yīng)TreeMenuAction,返回menu.jsp,而menu.jsp只包含menuString的值,注意在menu.jsp中的escape="false"

云自無(wú)心水自閑 2008-08-07 20:16 發(fā)表評(píng)論
]]>
我的struts2項(xiàng)目性能調(diào)優(yōu)三步曲(續(xù))http://m.tkk7.com/usherlight/archive/2008/07/12/214462.html云自無(wú)心水自閑云自無(wú)心水自閑Sat, 12 Jul 2008 10:57:00 GMThttp://m.tkk7.com/usherlight/archive/2008/07/12/214462.htmlhttp://m.tkk7.com/usherlight/comments/214462.htmlhttp://m.tkk7.com/usherlight/archive/2008/07/12/214462.html#Feedback3http://m.tkk7.com/usherlight/comments/commentRss/214462.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/214462.html最近,繼續(xù)研究了Struts2性能的調(diào)優(yōu)方法,總結(jié)了一下,得出新三步曲:

4. 使用FreeMarker的最新版本2.3.13,因?yàn)樵诎姹?.3.11中,F(xiàn)reeMarker針對(duì)性能進(jìn)行了改進(jìn),以下是FreeMarker2.3.11的release notes:
2.3.11
Date of release: 2007-12-04
This release contains several performance and usability improvements.

5. ognl2.7
所稱ognl2.7相對(duì)于2.6在性能上有了“顯著”的提升,于是下載了2.7以及2.7所需要的javassist-3.8.0.GA.jar

其實(shí),經(jīng)過(guò)上面2個(gè)步驟,我并沒(méi)有發(fā)現(xiàn)應(yīng)用的性能有顯著的改善,可能我的頁(yè)面中從ValueStack中的存取操作并不是特別多,也不是特別的復(fù)雜,所以,Ognl對(duì)我的影響并不明顯。

6. 最后使用了JProfiler對(duì)Tomcat進(jìn)行了監(jiān)控,最后發(fā)現(xiàn)問(wèn)題在自定義模板上,我將頁(yè)面的自定義模板全部刪除,果然頁(yè)面的響應(yīng)速度有了較大的提升。

 



云自無(wú)心水自閑 2008-07-12 18:57 發(fā)表評(píng)論
]]>
我的struts2項(xiàng)目性能調(diào)優(yōu)三步曲http://m.tkk7.com/usherlight/archive/2008/07/01/211869.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 01 Jul 2008 05:33:00 GMThttp://m.tkk7.com/usherlight/archive/2008/07/01/211869.htmlhttp://m.tkk7.com/usherlight/comments/211869.htmlhttp://m.tkk7.com/usherlight/archive/2008/07/01/211869.html#Feedback7http://m.tkk7.com/usherlight/comments/commentRss/211869.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/211869.html 一,根據(jù)struts2官方的性能調(diào)優(yōu)說(shuō)明進(jìn)行了一些參數(shù)的修改。
http://struts.apache.org/2.x/docs/performance-tuning.html
http://cwiki.apache.org/WW/performance-tuning.html

Turn off logging and devMode.(關(guān)閉logging和Devmode)
這個(gè)當(dāng)然沒(méi)問(wèn)題,但是全部關(guān)閉logging不現(xiàn)實(shí),我只是關(guān)閉了struts2相關(guān)package的logging

Do not use interceptors you do not need.
把struts.xml中不需要的interceptor統(tǒng)統(tǒng)刪除

Use the correct HTTP headers (Cache-Control & Expires).
不確定應(yīng)該如何修改

Copy the static content from the Struts 2 jar when using the Ajax theme (Dojo) or the Calendar tag.
關(guān)于這點(diǎn),后面會(huì)提到

Create a freemarker.properties file in your WEB-INF/classes directory.
照做

Create the freemarker.properties file and add the following setting (or whatever value you deem fitting):
template_update_delay=60000
照做

Enable Freemarker template caching
As of Struts 2.0.10, setting the property struts.freemarker.templatesCache to true will enable the Struts internal caching of Freemarker templates. This property is set to false by default.
照做

進(jìn)行上述修改后,發(fā)現(xiàn)頁(yè)面打開(kāi)的速度并沒(méi)有明顯的提高.

二,此時(shí)我已經(jīng)基本鎖定網(wǎng)頁(yè)打開(kāi)速度慢的原因與ajax(或者說(shuō)是dojo)有關(guān)。因?yàn)閐ojo的js庫(kù)大概有450K左右,先嘗試使用gzip壓縮javascript,減小傳輸量,看能否加快頁(yè)面的加載速度
在Tomcat的server.xml的connector中添加如下配置,激活gzip功能
 compression="on"
 compressionMinSize="2048"
 noCompressionUserAgents="gozilla, traviata"
 compressableMimeType="text/html,text/xml,text/javascript,application/x-javascript,application/javascript"
進(jìn)行上述修改后,發(fā)現(xiàn)頁(yè)面打開(kāi)的速度還是沒(méi)有明顯的提高.

三,經(jīng)過(guò)上述兩個(gè)實(shí)驗(yàn),覺(jué)得應(yīng)該是struts2所封閉的dojo的性能問(wèn)題了。于是引入JQuery.
JQuery的js文件最小是55K, gzip后應(yīng)該更小,頁(yè)面的響應(yīng)速度明顯改善(一個(gè)數(shù)量級(jí)以上的提高),主要原因在于與服務(wù)器交互的處理上極大地提升了效率。而且頁(yè)面處理代碼更加簡(jiǎn)潔明了。

最后,我刪除了所有的<s:head theme="ajax"/>和 <s:head/>(如果頁(yè)面中加入<s:head />,那么在Struts2生成的html中后包含dojo.js),使用JQuery來(lái)完成所有的Ajax和javascript功能。



云自無(wú)心水自閑 2008-07-01 13:33 發(fā)表評(píng)論
]]>
Struts2利用stream直接輸出Excelhttp://m.tkk7.com/usherlight/archive/2008/06/23/210135.html云自無(wú)心水自閑云自無(wú)心水自閑Mon, 23 Jun 2008 12:14:00 GMThttp://m.tkk7.com/usherlight/archive/2008/06/23/210135.htmlhttp://m.tkk7.com/usherlight/comments/210135.htmlhttp://m.tkk7.com/usherlight/archive/2008/06/23/210135.html#Feedback13http://m.tkk7.com/usherlight/comments/commentRss/210135.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/210135.html 

在利用網(wǎng)頁(yè)展示查詢結(jié)果,經(jīng)常會(huì)遇到要求導(dǎo)出成Excel的需求。采用這種方法可以定制輸出的格式和內(nèi)容(還不支持合并單元格和公式),生成真正的Excel格式(不是csv)的Excel。
一、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.i18n.encoding" value="UTF-8"/>

    <package name="demo" extends="struts-default">
        <action name="excel" method="execute" class="demo.ExcelAction">
                <result name="excel" type="stream">
                    <param name="contentType">application/vnd.ms-excel</param>    <!-- 注意這里的ContentType -->
                    <param name="inputName">excelStream</param>                   <!-- 這里需要和Action里的變量名一致 -->
                    <param name="contentDisposition">filename="standard.xls"</param>
                    <param name="bufferSize">1024</param>
                </result>
        </action>
    </package>
</struts>

二、Struts2的 Action

package demo;
public class ExcelAction {
    private InputStream excelStream; // 需要生成getter和setter

    public String execute() throws Exception {
        StringBuffer excelBuf = new StringBuffer();
        excelBuf.append("BookName").append("\t").append("Year").append("\t").append("author").append("\n");
        excelBuf.append("Thinking in Java").append("\t").append("2001").append("\t").append("Eckel").append("\n");
        excelBuf.append("Spring in action").append("\t").append("2005").append("\t").append("Rod").append("\n");
        String excelString = excelBuf.toString();
        logger.debug("result excel String: " + excelString);
        excelStream = new ByteArrayInputStream(excelString.getBytes(), 0, excelString.length());
        return "excel";
    }

    // getter and setter
    ...
}

三、Jsp頁(yè)面

<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <s:head />
 </head>

 <body>

    <s:form action="" method="post">
       <s:submit key="button.submit"/>
    </s:form>
 </body>
</html>



云自無(wú)心水自閑 2008-06-23 20:14 發(fā)表評(píng)論
]]>
用freemarker做模板創(chuàng)建一個(gè)struts2自定義標(biāo)簽http://m.tkk7.com/usherlight/archive/2008/04/11/192215.html云自無(wú)心水自閑云自無(wú)心水自閑Fri, 11 Apr 2008 08:09:00 GMThttp://m.tkk7.com/usherlight/archive/2008/04/11/192215.htmlhttp://m.tkk7.com/usherlight/comments/192215.htmlhttp://m.tkk7.com/usherlight/archive/2008/04/11/192215.html#Feedback4http://m.tkk7.com/usherlight/comments/commentRss/192215.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/192215.html 首先,在web項(xiàng)目的頁(yè)面根目錄下建立目錄template
然后創(chuàng)建目錄simple和xhtml,以上的目錄名是struts2缺省使用的,不同的主題使用相應(yīng)的目錄。然后再創(chuàng)建一個(gè)components目錄,在這個(gè)目錄下,創(chuàng)建一個(gè)property.ftl。 最后的目錄結(jié)構(gòu)如下:
template/simple/components/property.ftl
template/xhtml/components/property.ftl

然后在property.ftl中可以使用FreeMarker來(lái)定義新的模板(FreeMarker的具體語(yǔ)法可以查看FreeMarker的官方網(wǎng)站,相當(dāng)?shù)脑敿?xì)易懂):
<#include "/${parameters.templateDir}/${parameters.theme}/controlheader.ftl" />
<@s.if test="${parameters.value} == null || ${parameters.value} == '' ">&nbsp;</@s.if>
<@s.else><@s.property value="${parameters.value}" /></@s.else>
<#include "/${parameters.templateDir}/xhtml/controlfooter.ftl" />

以上是一個(gè)我自定義的模板,檢測(cè)結(jié)果是否為空字符串,如果是空的話,就輸出一個(gè)&nbsp; 這樣在輸出結(jié)果時(shí)表格的邊框線就是完整的了。

定義好之后,在jsp頁(yè)面中就可以這樣使用了:

<s:component template="/components/property.ftl" theme="simple">
  <s:param name="value" value="%{'bookName'}"/>
</s:component>

第一行中的目錄名從自components開(kāi)始,struts2會(huì)自動(dòng)在template目錄下去尋找,如是主題是simple, 就在simple目錄下找。
另外,param的語(yǔ)法要注意一下,%{}里面需要加一對(duì)引號(hào)


云自無(wú)心水自閑 2008-04-11 16:09 發(fā)表評(píng)論
]]>
Struts2中doubleselect的使用方法http://m.tkk7.com/usherlight/archive/2008/03/27/189145.html云自無(wú)心水自閑云自無(wú)心水自閑Thu, 27 Mar 2008 14:08:00 GMThttp://m.tkk7.com/usherlight/archive/2008/03/27/189145.htmlhttp://m.tkk7.com/usherlight/comments/189145.htmlhttp://m.tkk7.com/usherlight/archive/2008/03/27/189145.html#Feedback16http://m.tkk7.com/usherlight/comments/commentRss/189145.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/189145.html <s:doubleselect label="doubleselect test2" name="menu" list="#{'fruit':'Nice Fruits', 'other':'Other Dishes'}" doubleName="dishes" doubleList="top == 'fruit' ? {'apple', 'orange'} : {'monkey', 'chicken'}" />
上面的例子演示了doubleselect的基本用法,但是其list和doubleList都是固定的。尤其是doublelist的切換使用了3目運(yùn)算符 ? :,并沒(méi)有太大的實(shí)際使用價(jià)值。在實(shí)際應(yīng)用中,list往往是action返回的一個(gè)List<DataObject>,listKey和listValue來(lái)顯示第一級(jí)下拉框,doubleList往往是一個(gè)Map<Integer, List<DataObject>>,其中Map中的Key值是第一級(jí)下拉框的listKey。
舉個(gè)例子:
Data Object:
public class Book {
        
private int id;
        
private String name;
        
private int categoryId;

        
// getter and setter..
}


public class Category {
        
private int id;
        
private String name;

        
// getter and setter..
}


JSP:
<s:doubleselect list="categoryList" listKey="id" listValue="name"
   doubleName="bookId" doubleList="bookMap.get(top.id)" doubleListKey="id" doubleListValue="name" theme="simple"/>

此處要注意的是top的用法,開(kāi)始我以為top就是指代list的值,所以使用的是bookMap.get(top),但是二級(jí)下拉框一直是空白,后來(lái)我突然想到說(shuō)不定top是一個(gè)Category實(shí)例呢,嘗試了一下top.id,果然成功了。

Action:

public class DemoAction {
        
private Map<Integer, List<Book>> bookMap;
        
private List<Category> categoryList;

        
public String execute() throws Exception {
                categoryList 
= new ArrayList<Cateogry>();

                Category category;
                category 
= new Category();
                category.setId(
1);
                category.setName(
"Fiction");
                categoryList.add(category);
                category 
= new Category();
                category.setId(
2);
                category.setName(
"Java");
                categoryList.add(category);

 

                bookMap 
= new HashMap<Integer, List<Book>>();

                List
<Book> bookList = new ArrayList<Book>();
                Book book;
                book 
= new Book();
                book.setId(
1);
                book.setName(
"Harry Porter");
                book.setCategoryId(
1);
                bookList.add(book);

                book 
= new Book();
                book.setId(
2);
                book.setName(
"Nightmare");
                book.setCategoryId(
1);
                bookList.add(book);

                bookMap.put(
1, bookList);

 

                bookList 
= new ArrayList<Book>();
                book 
= new Book();
                book.setId(
3);
                book.setName(
"Thinking in Java");
                book.setCategoryId(
2);
                bookList.add(book);
                book 
= new Book();
                book.setId(
4);
                book.setName(
"Head First Design Patterns");
                book.setCategoryId(
2);
                bookList.add(book);

                bookMap.put(
2, bookList);


                
return SUCCESS;
        }

        
// getter and setter..
}





云自無(wú)心水自閑 2008-03-27 22:08 發(fā)表評(píng)論
]]>
使用struts2中的ognl表達(dá)式顯示數(shù)據(jù)表字典項(xiàng)的值http://m.tkk7.com/usherlight/archive/2008/03/17/186730.html云自無(wú)心水自閑云自無(wú)心水自閑Mon, 17 Mar 2008 04:09:00 GMThttp://m.tkk7.com/usherlight/archive/2008/03/17/186730.htmlhttp://m.tkk7.com/usherlight/comments/186730.htmlhttp://m.tkk7.com/usherlight/archive/2008/03/17/186730.html#Feedback8http://m.tkk7.com/usherlight/comments/commentRss/186730.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/186730.html 比如在一個(gè)圖書館系統(tǒng)中,書籍表(Book)會(huì)有一個(gè)分類字段,這時(shí)候我們一般會(huì)單獨(dú)建立一張分類表(Category),在書籍表只保存分類表的ID。
在用戶界面上顯示書籍明細(xì)的時(shí)候,會(huì)要求顯示CategoryID在Category表中對(duì)應(yīng)的名稱。
這樣通常的做法是把Book和Category兩張表進(jìn)行關(guān)聯(lián)。
但在實(shí)際應(yīng)用中,Category一般都是Cache在應(yīng)用服務(wù)器端,再使用數(shù)據(jù)表的連接就不夠高效。
我的做法是這樣的:在iBatis中使用SqlMap從表中將數(shù)據(jù)取出,此時(shí)不使用數(shù)據(jù)表的連接。
package com.demo;
public class Book {
      
/* 省略了getter和setter方法 */
        private int id;
        
private String name;
        
private int categoryId;
        
private String author;
}


package com.demo;

public class Category {
       
private static Map<Integer, Category> cacheMap;

        
/* 省略了這兩個(gè)屬性的getter和setter方法 */

        
private int id;
        
private String name;
       
public static Category getCategory(int id) {
             init();
            
return cacheMap.get(id);
        }
 
        
public static Map<Integer, Category> getCategoryMap() {
            init();
           
return cacheMap();
        }

       
private init() {
            
if ( cacheMap != null ) return;

            
// the code to load category from datebase
            
// 在這里為了演示的需要,使用以下代碼

             cacheMap 
= new HashMap<Integer, Category>();
             Category category 
= new Category();
             category.setId(
1);
             category.setName(
"Fiction");
             cacheMap.put(
1, category);
 
             category 
= new Category();
             category.setId(
2);
             category.setName(
"Cartoon");
        }
}



package com.demo;

public class BookAction  {
        
/* 省略了屬性的getter和setter方法 */
        Book book;

        
public String execute() {
                book 
= new Book();
                book.setId(
1);
                book.setName(
"Thinking in java");
                book.setCategoryId(
1);
                bookList.add(book);
                
                
return SUCCESS;                
        }
}

JSP:
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 
<head>
  
<s:head />
 
</head>

 
<body>

  
<table border="1">
    
<tr>
     
<td>
      
<s:text name="page.label.userName" />
     
</td>
     
<td>
      
<s:property value="book.name" />
     
</td>
    
</tr>
    
<tr>
     
<td>
      
<s:text name="page.label.category" />
     
</td>
     
<td>
       
<s:property value="@com.demo.Category@getCategory(book.categoryId).getName()"/></td>
    
</tr>
 
</body>
</html>





云自無(wú)心水自閑 2008-03-17 12:09 發(fā)表評(píng)論
]]>
stuts2中session timeout的處理(備忘)http://m.tkk7.com/usherlight/archive/2008/02/21/181026.html云自無(wú)心水自閑云自無(wú)心水自閑Thu, 21 Feb 2008 04:03:00 GMThttp://m.tkk7.com/usherlight/archive/2008/02/21/181026.htmlhttp://m.tkk7.com/usherlight/comments/181026.htmlhttp://m.tkk7.com/usherlight/archive/2008/02/21/181026.html#Feedback2http://m.tkk7.com/usherlight/comments/commentRss/181026.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/181026.htmlTomcat在后臺(tái)重起后,所有的session失效。如果客戶端繼續(xù)點(diǎn)擊了一個(gè)菜單項(xiàng),發(fā)出一個(gè)請(qǐng)求。會(huì)得到一個(gè)exception。

這時(shí)候,可以定義一個(gè)名為:sessionTimeout的global results

<result name="sessionTimeout">/WEB-INF/pages/session_timeout.jsp</result>

這樣,所有Action的session timeout都會(huì)被定向到指定的頁(yè)面



云自無(wú)心水自閑 2008-02-21 12:03 發(fā)表評(píng)論
]]>
Extjs Tree + JSON + Struts2 http://m.tkk7.com/usherlight/archive/2008/02/19/180590.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 19 Feb 2008 01:27:00 GMThttp://m.tkk7.com/usherlight/archive/2008/02/19/180590.htmlhttp://m.tkk7.com/usherlight/comments/180590.htmlhttp://m.tkk7.com/usherlight/archive/2008/02/19/180590.html#Feedback41http://m.tkk7.com/usherlight/comments/commentRss/180590.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/180590.html {"cls":"folder","id":10,"leaf":false,"children":[{"cls":"file","id":11,"leaf":true,"children":null,"text":"S600"},{"cls":"file","id":12,"leaf":true,"children":null,"text":"SLK200"}],"text":"Benz"}
而extjs需要的數(shù)據(jù)格式如下:
[{"cls":"folder","id":10,"leaf":false,"children":[{"cls":"file","id":11,"leaf":true,"children":null,"text":"S600"},{"cls":"file","id":12,"leaf":true,"children":null,"text":"SLK200"}],"text":"Benz"}]
區(qū)別很小,就只相差最外面的兩個(gè)方括號(hào)。但是少了這兩個(gè)方括號(hào),在json中,含義迥然不同,前者表示一個(gè)對(duì)象,而后者表示一個(gè)數(shù)組。而extjs中 tree的dataloader需要的數(shù)據(jù)必須是一個(gè)數(shù)組。而這樣的數(shù)據(jù)格式是json-plugin自動(dòng)生成的,無(wú)法改變。所以,我最后放棄了json -plugin,轉(zhuǎn)而使用json-lib來(lái)解決這個(gè)問(wèn)題。
1. 下載json-lib, http://json-lib.sourceforge.net/
2. lib目錄下的jar文件清單:
commons-beanutils-1.7.0.jar
commons-collections-3.2.jar
commons-digester-1.6.jar
commons-lang-2.3.jar
commons-logging-1.1.jar
dom4j-1.6.1.jar
ezmorph-1.0.4.jar
freemarker-2.3.8.jar
javassist-3.8.1.jar
json-lib-2.2.1-jdk15.jar
log4j-1.2.13.jar
ognl-2.6.11.jar
struts2-core-2.0.11.jar
xml-apis-1.0.b2.jar
xwork-2.0.4.jar


首先配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
  
<welcome-file-list>
    
<welcome-file>index.jsp</welcome-file>
  
</welcome-file-list>
  
<filter>
    
<filter-name>struts2</filter-name>
    
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
  
</filter>

  
<filter-mapping>
    
<filter-name>struts2</filter-name>
    
<url-pattern>/*</url-pattern>
  
</filter-mapping>
</web-app>

然后是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.devMode" value="true"/>
    
<constant name="struts.i18n.encoding" value="UTF-8"/>
    
<package name="person" extends="struts-default">
        
<action name="menus" method="execute" class="com.lab.MenuAction">
            
<result>/menu.jsp</result>
        
</action>
    
</package>
</struts>

3. 樹(shù)的節(jié)點(diǎn)模型(省略了getter,setter)
public class Menu {
    
private int id;
    
private String text;
    
private boolean leaf;
    
private String cls;
    
private List<Menu> children;
}

4. action
package com.lab;

import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONArray;

public class MenuAction {
    
private String menuString;
   
    
private List<Menu> menus;
   
    
public String execute() {

        menus 
= new ArrayList<Menu>();
       
        Menu benz 
= new Menu();
        benz.setText(
"Benz");
        benz.setCls(
"folder");
        benz.setLeaf(
false);
        benz.setId(
10);
        menus.add(benz);
       
        List
<Menu> benzList = new ArrayList<Menu>();
        benz.setChildren(benzList);
       
        Menu menu;
        menu 
= new Menu();
        menu.setText(
"S600");
        menu.setCls(
"file");
        menu.setLeaf(
true);
        menu.setId(
11);
        benzList.add(menu);
        menu 
= new Menu();
        menu.setText(
"SLK200");
        menu.setCls(
"file");
        menu.setLeaf(
true);
        menu.setId(
12);
        benzList.add(menu);
       
        Menu bmw 
= new Menu();
        bmw.setText(
"BMW");
        bmw.setCls(
"folder");
        bmw.setLeaf(
false);
        bmw.setId(
20);
        menus.add(bmw);
       
        List
<Menu> bmwList = new ArrayList<Menu>();
        bmw.setChildren(bmwList);
       
        menu 
= new Menu();
        menu.setText(
"325i");
        menu.setCls(
"file");
        menu.setLeaf(
true);
        menu.setId(
21);
        bmwList.add(menu);
       
        menu 
= new Menu();
        menu.setText(
"X5");
        menu.setCls(
"file");
        menu.setLeaf(
true);
        menu.setId(
22);
        bmwList.add(menu);
       
        JSONArray jsonObject 
= JSONArray.fromObject(menus);
        
try {
            menuString 
= jsonObject.toString();
        } 
catch (Exception e) {
            menuString 
= "ss";
        }

        
return "success";
    }

    
public String getMenuString() {
        
return menuString;
    }

    
public void setMenuString(String menuString) {
        
this.menuString = menuString;
    }
}

5. menu.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:property value="menuString" escape="false"/>

6. html頁(yè)面和js
我使用的就是extjs的example中的reorder.html和reorder.js,更改了reorder.js中treeloader的dataurl: menus.action
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Reorder TreePanel</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css" />

    
<!-- GC -->
     
<!-- LIBS -->
     
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
     
<!-- ENDLIBS -->
 
    
<script type="text/javascript" src="extjs/ext-all.js"></script>
<script type="text/javascript" src="reorder.js"></script>

<!-- Common Styles for the examples -->
<link rel="stylesheet" type="text/css" href="extjs/resources/css/example.css" />
</head>
<body>
<script type="text/javascript" src="../examples.js"></script><!-- EXAMPLES -->
<h1>Drag and Drop ordering in a TreePanel</h1>
<p>This example shows basic drag and drop node moving in a tree. In this implementation there are no restrictions and 
anything can be dropped anywhere except appending to nodes marked 
&quot;leaf&quot; (the files). <br></p>
<p>Drag along the edge of the tree to trigger auto scrolling while performing a drag and drop.</p>
<p>In order to demonstrate drag and drop insertion points, sorting was <b>not</b> enabled.</p>
<p>The data for this tree is asynchronously loaded with a JSON TreeLoader.</p>
<p>The js is not minified so it is readable. See <href="reorder.js">reorder.js</a>.</p>

<div id="tree-div" style="overflow:auto; height:300px;width:250px;border:1px solid #c3daf9;"></div>

</body>
</html>



js:
/*
 * Ext JS Library 2.0.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 
*/

Ext.onReady(
function(){
    
// shorthand
    var Tree = Ext.tree;
   
    
var tree = new Tree.TreePanel({
        el:'tree
-div',
        autoScroll:
true,
        animate:
true,
        enableDD:
true,
        containerScroll: 
true,
        loader: 
new Tree.TreeLoader({
            dataUrl:'http:
//localhost:8080/lab/menus.action'
        })
    });

    
// set the root node
    var root = new Tree.AsyncTreeNode({
        text: 'Ext JS',
        draggable:
false,
        id:'source'
    });
    tree.setRootNode(root);

    
// render the tree
    tree.render();
    root.expand();
});

我已經(jīng)上傳了完整的War文件(包含所有源代碼),見(jiàn):Extjs Tree + JSON + Struts2 的所有示例源代碼和war文件下載



云自無(wú)心水自閑 2008-02-19 09:27 發(fā)表評(píng)論
]]>
Struts2中實(shí)現(xiàn)可編輯的表格http://m.tkk7.com/usherlight/archive/2008/02/12/179717.html云自無(wú)心水自閑云自無(wú)心水自閑Tue, 12 Feb 2008 13:06:00 GMThttp://m.tkk7.com/usherlight/archive/2008/02/12/179717.htmlhttp://m.tkk7.com/usherlight/comments/179717.htmlhttp://m.tkk7.com/usherlight/archive/2008/02/12/179717.html#Feedback2http://m.tkk7.com/usherlight/comments/commentRss/179717.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/179717.html
public class Person {
int id;
String name;
int age;
float height;
}

這是一個(gè)POJO,getter和setting省略了。

action中可以這樣使用:

public class MyAction {
public List getPeopleList() { … }
public void setPeopleList( List peopleList ) { … }

}
在我們使用Person類之前,需要添加一個(gè)配置文件,MyAction-conversion.properties,把這個(gè)文件和MyAction放在一起。
這個(gè)文件里只有一行內(nèi)容:
Element_peopleList=Person
前綴Element_是一個(gè)常量,表明等號(hào)左邊的表達(dá)式中跟在這個(gè)常量后面的是Action類中一個(gè)List類型的字段名。
等號(hào)右邊的表達(dá)式是全類名(包含package)
下面是一個(gè)頁(yè)面的代碼片段:
<s:form action="update" method="post" >
<s:iterator value="peopleList" status="stat">
<s:hidden
name="peopleList[%{#stat.index}].id"
value
="%{peopleList[#stat.index].id}"/>
<s:textfield label="Name"
name
="peopleList[%{#stat.index}].name"
value
="%{peopleList[#stat.index].name}"/>
<s:textfield label="Age"
name
="peopleList[%{#stat.index}].age"
value
="%{peopleList[#stat.index].age}" />
<s:textfield label="Height"
name
="peopleList[%{#stat.index}].height"
value
="%{peopleList[#stat.index].height}"/>
<br/>
</s:iterator>
<s:submit value="Update"/>
</s:form>


使用這段代碼,Struts2會(huì)創(chuàng)建一個(gè)Person類的ArrayList,并且用setPersonList這個(gè)方法把頁(yè)面表格中的值傳遞回Action。
如果你是想從用戶界面中動(dòng)態(tài)創(chuàng)建列表值,需要允許Struts2給列表中類的實(shí)例。那么在配置文件MyAction-conversion.properties中添加一行:
CreateIfNull_peopleList = true

云自無(wú)心水自閑 2008-02-12 21:06 發(fā)表評(píng)論
]]>
Struts2 and Ajax --使用Dojo和Divhttp://m.tkk7.com/usherlight/archive/2008/02/10/179572.html云自無(wú)心水自閑云自無(wú)心水自閑Sun, 10 Feb 2008 12:56:00 GMThttp://m.tkk7.com/usherlight/archive/2008/02/10/179572.htmlhttp://m.tkk7.com/usherlight/comments/179572.htmlhttp://m.tkk7.com/usherlight/archive/2008/02/10/179572.html#Feedback6http://m.tkk7.com/usherlight/comments/commentRss/179572.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/179572.html閱讀全文

云自無(wú)心水自閑 2008-02-10 20:56 發(fā)表評(píng)論
]]>
struts2使用iterator標(biāo)簽顯示嵌套Maphttp://m.tkk7.com/usherlight/archive/2008/01/25/177741.html云自無(wú)心水自閑云自無(wú)心水自閑Fri, 25 Jan 2008 05:16:00 GMThttp://m.tkk7.com/usherlight/archive/2008/01/25/177741.htmlhttp://m.tkk7.com/usherlight/comments/177741.htmlhttp://m.tkk7.com/usherlight/archive/2008/01/25/177741.html#Feedback10http://m.tkk7.com/usherlight/comments/commentRss/177741.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/177741.html<%@ taglib prefix="s" uri="/struts-tags"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    
<head>
        
<s:head />
    
</head>

    
<body>

        
<table border="1">
            
<s:iterator value="dataMap.keySet()" id="class">
                
<s:iterator value="dataMap.get(#class).keySet()" id="group">
                
<tr>
                    
<td><s:property value="group"/></td>
                    
<s:iterator value="dataMap.get(#class).get(#group).values()" id="name">
                        
<td><s:property value="name"/></td>
                    
</s:iterator>
                
</tr>
                
</s:iterator>
            
</s:iterator>
        
</table>
    
</body>
</html>


云自無(wú)心水自閑 2008-01-25 13:16 發(fā)表評(píng)論
]]>
Struts2中對(duì)于radio list的預(yù)選(pre select),即:使一個(gè)值被默認(rèn)選中http://m.tkk7.com/usherlight/archive/2008/01/24/177589.html云自無(wú)心水自閑云自無(wú)心水自閑Thu, 24 Jan 2008 14:06:00 GMThttp://m.tkk7.com/usherlight/archive/2008/01/24/177589.htmlhttp://m.tkk7.com/usherlight/comments/177589.htmlhttp://m.tkk7.com/usherlight/archive/2008/01/24/177589.html#Feedback4http://m.tkk7.com/usherlight/comments/commentRss/177589.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/177589.html在Struts2中,radio標(biāo)簽可以使用一個(gè)list來(lái)輸出一組radio按鈕,
        <s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" />
但是如何設(shè)置其中一個(gè)被默認(rèn)選中。

查閱了struts2的文檔,發(fā)現(xiàn)radio標(biāo)簽有一個(gè)value屬性是用于對(duì)radio的進(jìn)行預(yù)選的: http://struts.apache.org/2.x/docs/radio.html
value: Preset the value of input element.
于是,進(jìn)行了試驗(yàn),<s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" value="male" />
結(jié)果失敗了。male的值并沒(méi)有被選中,經(jīng)過(guò)反復(fù)研究,終于得到了正確的結(jié)果:
<s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" value="'male'" />
看到其中的區(qū)別了嗎,就是多了兩個(gè)單引號(hào)。
我認(rèn)為這是因?yàn)関alue屬性的特性引起的。如果male沒(méi)有加引號(hào),那么struts2會(huì)去值的堆棧中尋找變量名為male的值,結(jié)果找不到。
加上單引號(hào)后,struts2(應(yīng)該是ognl)把'male'認(rèn)為是一個(gè)簡(jiǎn)單的字符串。

這樣,radio就能夠正確地匹配到值,使指定的值默認(rèn)被選中



云自無(wú)心水自閑 2008-01-24 22:06 發(fā)表評(píng)論
]]>
Struts2動(dòng)態(tài)返回Xmlhttp://m.tkk7.com/usherlight/archive/2007/12/14/167858.html云自無(wú)心水自閑云自無(wú)心水自閑Fri, 14 Dec 2007 13:14:00 GMThttp://m.tkk7.com/usherlight/archive/2007/12/14/167858.htmlhttp://m.tkk7.com/usherlight/comments/167858.htmlhttp://m.tkk7.com/usherlight/archive/2007/12/14/167858.html#Feedback6http://m.tkk7.com/usherlight/comments/commentRss/167858.htmlhttp://m.tkk7.com/usherlight/services/trackbacks/167858.html 開(kāi)始進(jìn)行的都比較順利,但是客戶端和服務(wù)端一連起來(lái)就出問(wèn)題,頁(yè)面在加載Xml的時(shí)候總是彈出一個(gè)對(duì)話框,說(shuō)是加載的xml格式不正確。但是我在IE中直接輸入Action,頁(yè)面顯示的結(jié)果十分正確,沒(méi)有問(wèn)題。后來(lái),無(wú)意中我查看了返回xml頁(yè)面的源文件,這才發(fā)現(xiàn)了問(wèn)題。
原來(lái),xml的<和>全都被轉(zhuǎn)換成&lt;和&gt;了。
我一開(kāi)始是想在后臺(tái)考慮如何對(duì)字符串進(jìn)行轉(zhuǎn)換,后來(lái)在查struts2文檔的時(shí)候發(fā)現(xiàn),<s:property有一個(gè)escape屬性,可以完美地解決這個(gè)問(wèn)題,<s:property value="menuXmlString" escape="false"/>

例子已經(jīng)整理出來(lái)了:http://m.tkk7.com/usherlight/archive/2008/08/07/220756.html

云自無(wú)心水自閑 2007-12-14 21:14 發(fā)表評(píng)論
]]>
主站蜘蛛池模板: 小草在线看片免费人成视久网| 亚洲一区动漫卡通在线播放| 亚洲国产美女在线观看 | 亚洲成a人片在线观看日本麻豆| 亚洲国产一成久久精品国产成人综合| 亚洲综合av一区二区三区不卡| 日本妇人成熟免费中文字幕| 亚洲第一成年网站大全亚洲| 猫咪免费观看人成网站在线| 免费国产a国产片高清网站| 美女被免费视频网站| 亚洲欧洲日本在线| 国产午夜成人免费看片无遮挡 | 黄页网站在线观看免费| 亚洲中文字幕视频国产| 三级毛片在线免费观看| 久久久久亚洲av无码专区喷水| 久久久久久毛片免费播放| 亚洲狠狠爱综合影院婷婷| 久久国产精品免费一区| 国产免费卡一卡三卡乱码| 亚洲自偷自偷精品| 美女视频黄免费亚洲| 久久久亚洲精华液精华液精华液 | 天天摸天天碰成人免费视频| 日韩亚洲人成在线综合| 222www免费视频| 国产亚洲精品自在久久| 中国xxxxx高清免费看视频| 亚洲国产精品久久久久秋霞小 | 特级毛片全部免费播放a一级 | av永久免费网站在线观看| 亚洲自偷自拍另类图片二区| 免费黄色一级毛片| 中文字幕手机在线免费看电影| 亚洲人成电影在线天堂| 日本19禁啪啪无遮挡免费动图| 中文字幕在线观看亚洲视频| 免费国产成人午夜私人影视| 午夜免费福利小电影| 久久亚洲精品无码av|