??xml version="1.0" encoding="utf-8" standalone="yes"?>
1.q程对象是引用传递?br />q个引用是位于client端的stubQv着代理的作用,q程对象实现了的q程接口Q作Z理的stub也全部实玎ͼ
2.本地对象是g递,x贝?br />~省的话Q所有的属性都?x)被拯Q除了标CZؓ(f)static或transient的属性之外。这U缺省行为是可以在类里被覆盖的?br />q程对象的引用传递意味着对远E方法调用的对象的状态所作的M改变都将反映到该stub所对应的远E对象上厅R当一个远E对象被传递时Q接受者只能看到远E接口里定义的方法,而不能看到远E对象里定义的本地方法?br />本地对象的g递意味着MҎ(gu)受者的对象的状态的改变都不?x)媄响到发送者那里的对象Q反之亦然?img src ="http://www.aygfsteel.com/koradji/aggbug/351135.html" width = "1" height = "1" />
]]>
W二步,实现remote接口Q?br />
实现接口里定义的各个Ҏ(gu)Q?br />
(optional)定义本地Ҏ(gu)Q即未在接口里定义的Ҏ(gu)Qclient端看不到Q?br />
定义static mainҎ(gu)Q这里需要实C列几步:(x)
System.setSecurityManager(new RMISecurityManager()); //创徏q安装安全管理器
取得args[0]参数Q实例化remotecobjQ?br />
Naming.rebind(args[0], obj); //l定名字和对?br />
W三步,创徏客户端类Q?br />
主要是定义static mainҎ(gu)Q这里需要实C列几步:(x)
取得args[0]指定的server名字Q?br />
用Naming.lookup(server名字)查找l定的对象objQ?br />
调用obj的各个方法,像本地调用一P
W四步,创徏policy文gQ例如,创徏rmi.policy文gQ?br />
grant {
// Allow everything for now
permission java.security.AllPermission;
};
注意Q以上仅是用作练?fn)?br />
W五步,启动rmiregistryQ?br />
在dosH口下,输入Qstart rmiregistry(回R)
?x)弹出新H口Q表C正在运行rmiregistryQ?br />
注意Q一定要在remotecL在的目录下执行该命o(h)?/span>
W六步,启动server端程序:(x)
输入命o(h)Qjava server?-Djava.security.policy="policy完整路径?
W七步,启动client端程序:(x)
输入命o(h)Qjava server?br />
现在可以看到client-server间的通讯了?br />
补充Q实际测试发玎ͼ用一个helper对象装所有需要传lremotecȝҎ(gu)参数Q比起一个个参数传递性能要好很多?br />
helper对象一定要implements Serializable接口?/span>
]]>
问题解决了?br />
2.接着在执行javaE序时又报错QNoClassDefFoundErrorQ可是明明两个class文g都在Q这是ؓ(f)什么呢Q?br />
后来Q查了google才明白,原来是classpath里一定要在\径上加上“.;”Q漏掉这个小的点就?x)报q种错误?br />
环境问题Q\径问题这些L让java开发者抓?)
]]>
在struts2里,资源文g被分成了三个U别Q类U别Q包U别Q全局U别?br />
执行Ӟ按照从到大的序依次搜烦资源文g里的key|直至扑ֈ?br />
cȝ别的文g名定义:(x)Actioncd_语言码_国家?propertiesQ比如:(x)LoginAction_en_US.propertiesQLoginAction_zh_CN.propertiesQ?br />
如果是在全局中定义资源文Ӟ则需要在struts.xml里配|,例子Q?lt;constant name="struts.custom.i18n.resources" value="message" />Q其中message源文件的起始名;
全局资源文g的位|在src\下?br />
如何写中文的资源文gQ?br />
对于用于中文昄的资源文Ӟ以前需要用java自带的native2ascii.exe中文内容{换成对应的unicodeQ比较麻烦,而现在可以用eclipse的插件自动{换?br />
eclipse插gQ?span style="background-color: yellow">propertieEdit(一Ƅ日本人开发的开源插Ӟ可直接输入中文,自动转换)
本地下蝲linkQ?a href="/Files/koradji/propertieEdit.zip">/Files/koradji/propertieEdit.zip
下蝲后,里面的目录拯到eclipse下对应的目录里,重新启动eclipse可以了?可能需要在启动命o(h)里加?clean)?br />
在jsp里读取资源文件的Ҏ(gu)Q?/u>
画面上的文字采用<s:text name="key" />写;
其他的,比如按钮的valueQtextfield的label{采?lt;%{getText('key')}>写,例子Q?lt;s:submit action="confirm" value="%{getText('confirm.button.label')}" /> Q?br />
或者,也可以用这L(fng)写法Q?lt;s:textfield name="username" key="page.index.text.username"></s:textfield>
使用<s:i18n>可以指定临时的资源文Ӟ
例子1Q?br />
<s:i18n name="temp"> ----- baseName对应名称的资源文件名
<s:text name="info"> ----- info源文件中的key
<s:param>张三</s:param> ---- 指定W一个参?nbsp; {0}
<s:param>23</s:param> ---- 指定W二个参?nbsp; {1}
</s:text>
</s:i18n>
例子2Q?br />
<s:i18n name="org.scorpio.jh.struts2.i18n.web.action.LoginAction">
<s:text name="page.index.text.username"></s:text>
<s:text name="page.index.text.password"></s:text>
</s:i18n>
没有实际应用q,猜测可能是在面上指定某个区域可以显CZdefault locale不同的语a文字Q?br />
在java里读取资源文件的Ҏ(gu)Q?/u>
Actionc里(需要承ActionSupport)Q用getText(String key)Ҏ(gu)p取得资源文g里的|
Business Servicesc里Q用ResourceBundle.getBundle(资源文g?.getString(key)Ҏ(gu)取得|
如何切换画面语言Q?/u>
在jsp里,在适当的位|放入下面的代码Q?br />
<s:url id="url" action="UnsubscribeNL_language">
<s:param name="request_locale">en_US</s:param>
</s:url>
<s:a href="%{url}">English</s:a><br>
<s:url id="url" action="UnsubscribeNL_language">
<s:param name="request_locale">zh_CN</s:param>
</s:url>
<s:a href="%{url}">体中?lt;/s:a>
在发送请求时Qstruts?x)搜索拦截request_locale变量Qƈ该变量D为default localeQ?br />
在Actionc里加入一个方法:(x)public String language()Q运行初始化q回本画面即可;
]]>
<s:checkboxlist name="" list="" listKey="" listValue="" value="" />
name-定义标签名,用于接收画面上选中的复选框Q故应与Action里定义的属性一_(d)且多为数l;
list-定义集合变量Q用于输出复选框到画面上Q一般在Action里定义一个List或Map属性;
listKey-如果在Action里定义的是一个ListQ则往往?x)在List里定义一个BeanQ它只有两个属性,其中一?比如id)在q里讄Q?br />
如果在Action里定义的是一个MapQ则Map的key在q里讄Q?br />
listValue-如果在Action里定义的是一个ListQ则往往?x)在List里定义一个BeanQ它只有两个属性,另外一?比如name)在q里讄Q?br />
如果在Action里定义的是一个MapQ则Map的value在q里讄Q?br />
value-用于回显画面上被选中的复选框Q假如画面有输入查,如果有错则返回原画面q显C出错信息,q时候就需要用它?br />
一般把它设成和name一致就可以了?br />
注意点:(x)
Z能正显C已被选中的复选框Q一定要使得name的数l类型与listKey的类型一致?br />
比如Qname设成String[] usersQ则listKeyp设成String idQ如果name设成Integer[] usersQ则listKeyp设成Integer idQ?br />
修改ftl文g改变输出方式Q?/u>
1.搜烦struts2-core-xxx.jarQ找到checkboxlist.ftl文gQ拷贝出来;
2.在自q工程的src下新建template.simple包,攄上述文gQ?br />
3.用文本编辑器打开该文Ӟ修改成自己希望输出的格式Q保存,OKQ?br />
例子Q?/u>
希望画面上每3个复选框输出Z行?/span>
<#--
/*
* $Id: checkboxlist.ftl 804072 2009-08-14 03:16:35Z musachy $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<#assign itemCount = 0/>
<#if parameters.list?exists>
<@s.iterator value="parameters.list">
<#assign itemCount = itemCount + 1/>
<#if parameters.listKey?exists>
<#assign itemKey = stack.findValue(parameters.listKey)/>
<#else>
<#assign itemKey = stack.findValue('top')/>
</#if>
<#if parameters.listValue?exists>
<#assign itemValue = stack.findString(parameters.listValue)/>
<#else>
<#assign itemValue = stack.findString('top')/>
</#if>
<#assign itemKeyStr=itemKey.toString() />
<#if (itemCount-1)%3 == 0>
<tr>
</#if>
<td>
<input type="checkbox" name="${parameters.name?html}" value="${itemKeyStr?html}" id="${parameters.name?html}-${itemCount}"<#rt/>
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>
</#if>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
<#if parameters.title?exists>
title="${parameters.title?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
<#include "/${parameters.templateDir}/simple/common-attributes.ftl" />
/>
<label for="${parameters.name?html}-${itemCount}" class="checkboxLabel">${itemValue?html}</label>
</td>
<#if itemCount%3 == 0>
</tr>
</#if>
</@s.iterator>
</#if>
<input type="hidden" id="__multiselect_${parameters.id?html}" name="__multiselect_${parameters.name?html}" value=""<#rt/>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
/>
]]>
*ZIP嶌惉僣乕?br />
=============================================================================*/
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.zip.CRC32;
import java.util.zip.CheckedOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ZipCompressor {
static final int BUFFER = 8192;
private File zipFile;
public ZipCompressor(String pathName) {
zipFile = new File(pathName);
}
public void compress(String srcPathName) {
File file = new File(srcPathName);
if (!file.exists())
throw new RuntimeException(srcPathName + "懚匧(do)偟側?);
try {
FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
CheckedOutputStream cos = new CheckedOutputStream(fileOutputStream,
new CRC32());
ZipOutputStream out = new ZipOutputStream(cos);
String basedir = "";
compress(file, out, basedir);
out.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void compress(File file, ZipOutputStream out, String basedir) {
/* 僨傿儗僋僩儕偲偐僼傽僀儖偲偐偦傟偧傟張偟傑偡 */
if (file.isDirectory()) {
System.out.println("埑弅? + basedir + file.getName());
this.compressDirectory(file, out, basedir);
} else {
System.out.println("埑弅? + basedir + file.getName());
this.compressFile(file, out, basedir);
}
}
/** 僨傿儗僋僩儕傪埑?*/
private void compressDirectory(File dir, ZipOutputStream out, String basedir) {
if (!dir.exists())
return;
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
compress(files[i], out, basedir + dir.getName() + "/");
}
}
/** 暥審傪埑?*/
private void compressFile(File file, ZipOutputStream out, String basedir) {
if (!file.exists()) {
return;
}
try {
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(file));
ZipEntry entry = new ZipEntry(basedir + file.getName());
out.putNextEntry(entry);
int count;
byte data[] = new byte[BUFFER];
while ((count = bis.read(data, 0, BUFFER)) != -1) {
out.write(data, 0, count);
}
bis.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}