锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 娉ㄦ剰鐨勬槸濡傛灉浣跨敤Carlender鏉ヤ繚瀛樻椂闂?鍥犱負涓婇潰瑕佹眰浼犲叆鐨勬槸Data瀵硅薄錛屽洜姝ら渶瑕佷嬌鐢–arlender.getTime()鏂規硶 <ww:text name="'global.format.date'"> 榪欓噷浣跨敤鐨勬槸<ww:param/>鏍囩鏉ヤ紶閫掑弬鏁幫紝铏界劧涔熷彲浠ヤ嬌鐢?<ww:text name="'format.date'" value0= "'birthday.time()'"/> 紱佺敤value0灞炴х殑璇存槑錛?br />
澶у鍙互鎵懼埌text鏍囩鐨勬簮浠g爜,鍦╟om.opensymphony.webwork.views.jsp.ui.TextTag涓細 鑰冭檻鐩墠鍦ㄩ」鐩腑浣跨敤鏈澶氱殑鏄樉紺洪檮浠跺ぇ灝?瀹氫箟浠ヤ笅鏍煎紡: 濡俛ction鏈夋柟娉?br />
public long getFilesize(); 榪斿洖鐨勫ぇ灝忔槸浠yte涓哄崟浣嶏紝鍦ㄦ樉紺烘椂閫氬父鏄互k鎴朚鏄劇ず 姣旇緝閬楁喚鐨勬槸浼間箮娌℃湁鍔炴硶鍦ㄨ祫婧愭枃浠朵腑榪涜榪欎釜/1024鐨勮繍綆楋紝璇曡繃{0/1024,number,##0.00'K'} 鏃犳硶瑙f瀽銆傚彧濂藉湪jsp閲岄潰鐢?value="filesize/1024"鏉ヨ綆楀疄闄呭箋備笉鐭ラ亾榪欓噷鏈夋病鏈夊埆鐨勬洿濂界殑瀹炵幇鏂瑰紡錛?br />
<action name="updatePassword" class="userAction" method="updatePassword">
<result name="input">/account/updatePassword.jsp</result>
<result name="success" type="redirect" >/account/updatePassword.jsp</result>
</action>
娉ㄦ剰:
濡傛灉灝唕esult鏍囩鐨則ype灞炴ц緗負redirect鍒欏湪Action鍗充嬌浣跨敤浜?br />
addActionMessage(getText("updatePassword.success"));
鍦↗SP欏甸潰涔熶笉鑳芥樉紺虹浉搴旂殑淇℃伅
]]>
鍓嶈█錛氬ぇ姒傚湪鍘誨勾6鏈堢殑鏃跺欙紝鎴戜滑鍥㈤槦寮濮嬩嬌鐢╳ebwork鏉ユ浛浠truts錛屽垰寮濮嬪ぇ瀹墮兘娌℃湁緇忛獙錛屼負浜嗘牸寮忓寲杈撳嚭鏃墮棿鍜屾暟瀛楋紝鎯沖嚭浜嗗緢澶氱幇鍦ㄧ湅鏉ョ絎ㄧ殑鍌誨偦鐨勬柟娉曘傚悗鏉ヤ亢鎵懼埌浜嗚繖涓柟娉曪紝璇曢獙浜嗕竴涓嬩箣鍚庡彂浜嗕笅闈㈣繖涓猠mail緇欎簡team member, 浠婂ぉ涓浣嶅悓浜嬮棶璧瘋繖涓棶棰橈紝淇轟粠鏁頒互鍗冭鐨勫凡鍙戦侀偖浠朵腑鎵懼埌浜嗚繖涓笢瑗匡紝鎯蟲兂鍐沖畾鏁寸悊鍑烘潵銆傜粰澶у鍒嗕韓涓涓嬶紝欏轟究緇欐垜鑷繁鍋氫釜澶囦喚錛屽懙鍛碉紝鍚庤呭熀鏈笂鏄亢鍐檅log鐨勪竴涓噸瑕佺敤閫斻?br />
鍒嗕韓涓涓湪WebWork涓浣曟牸寮忓寲鏄劇ず鏁板瓧鍜屾棩鏈熺殑鏂規硶錛?
鍏蜂綋鐨勫仛娉曡繖閲屾湁璇︾粏鐨勮鏄庯細
http://wiki.opensymphony.com/display/WW1/How+to+format+dates+and+numbers?showComments=true
涓嬮潰鏄」鐩腑鎺ㄨ崘浣跨敤鐨勬椂闂存牸寮?
#format
global.format.date={0,date,yyyy-MM-dd}
global.format.time={0,date,HH:mm:ss}
global.format.datetime={0,date,yyyy-MM-dd HH:mm:ss}
浠嶤arlender涓幏鍙朌ate:
<ww:param value="'birthday.time()'"/>
</ww:text>
浣嗘槸鍚庨潰鐨勮繖涓柟娉曞湪webwork鐨勬柊鐗堟湰涓凡緇忚瑕佹眰涓嶈浣跨敤錛屽ぇ瀹惰繕鏄敖閲忎嬌鐢?<ww:param/>鏍囩
public void setValue0(String aName) {
LOG.warn("The value attributes of TextTag are deprecated.");
value1Attr = aName;
}
瀵逛簬鏁板瓧鐨勬牸寮忓寲錛岃繖閲屾湁涓や釜鍙傝冿細
global.format.percent = {0,number,##0.00'%'}
global.format.money = {0,number,$##0.00}
global.format.size.k={0,number,##0.00'K'}
global.format.size.m={0,number,##0.00'M'}
global.format.size.g={0,number,##0.00'G'}
鍒欐樉紺烘椂:
<ww:text name="'global.format.size.k'">
<ww:param value="filesize/1024"/>
</ww:text>
<ww:text name="'global.format.size.m'">
<ww:param value="filesize/1048576"/>
</ww:text>
<ww:text name="'global.format.size.g'">
<ww:param value="filesize/1073741824"/>
</ww:text>
鎭╋紝欏轟究鍐嶄粙緇嶄竴涓嬪綋鏃朵亢浠瑃eam鎯沖嚭鏉ョ殑絎ㄧ鐨勬柟娉曪紝涓嶈瑙佺瑧鍟婏紝浠ヤ笂闈㈢殑鏄劇ず鏂囦歡澶у皬涓轟緥錛屾兂鍒扮殑鏂規硶澶ц嚧鏈変互涓嬪嚑縐嶏細
1. 鐩存帴杈撳嚭瀛楃涓茬殑緇撴灉
getFileSizeString(), 鍦ㄩ噷闈㈢敤java浠g爜鍒ゆ柇澶у皬騫剁敓鎴愯濡?1.2k", "31.2M"鐨勭粨鏋滆繑鍥?br />
2. 鎻愪緵澶氫釜鍑芥暟
getFileSizeByte(), getFileSizeK(), getFileSizeM(), getFileSizeG()
3.浣跨敤javascript鍦╟lient绔牸寮忓寲
<script type = "text/javascript">
var resultNum = <ww:property value="fileSize" />;
resultNum = format(resultNum);//綾諱技鐨勫嚱鏁?nbsp;
document.write(resultNum);
</script>
4.浣跨敤鑷畾涔夋爣絳?/p>
--------------------------------------------------------------------------------------------------------------
struts2涓牸寮忓寲杈撳嚭鏁板瓧鍜屾棩鏈熺殑鏂規硶
璧勬簮鏂囦歡
......
#鏍煎紡鍖栨暟瀛楁垨鏃墮棿杈撳嚭
global.format.date={0,date,yyyy-MM-dd}
global.format.money={0,number,錕?#0.00 '鍏?}
......
JSP鏂囦歡
鏍煎紡鍖栨椂闂? <s:text name="global.format.date"><s:param value="publishTime"></s:param></s:text>
鏍煎紡鍖栨暟瀛? <s:text name="global.format.money"><s:param value="price"/></s:text>
hibernate鐨凞etachedCriteria鏌ヨ
鍥句功鍜屼綔鑰呬箣闂存槸澶氬澶氬叧緋?鐜板湪鐭ラ亾浣滆?瑕佹煡璇ヤ綔鑰呮墍鍐欑殑鍥句功,鏉′歡搴旇鎬庢牱鍐欏晩
鎴戣繖鏍峰啓鏄敊璇殑
detachedCriteria.add(Restrictions.eq("authors", authorSet));璇烽棶榪欏彞搴旇鎬庢牱鍐欐墠瀵?
authorSet鏄竴涓猄et綾誨瀷鐨勫彉閲?br />
瑙e喅鍔炴硶
detachedCriteria.createAlias("authors", "auths").add( Restrictions.in("auths.name", authorSet));
涓嶈繃鍑哄張鍑虹幇浜嗘柊鐨勯棶棰?br />
鏌ュ緱鐨勭粨鏋滀互鏁扮粍鐨勬柟寮忚繑鍥?鏁扮粍鍖呭惈浜咮ook鍜孉uthor涓や釜瀵硅薄浜嗭紝鑳戒笉鑳借緗竴涓?璁╁畠鍙繑鍥濨ook瀵硅薄灝卞ソ浜?img src="/CuteSoft_Client/CuteEditor/images/emsmileo.gif" align="absMiddle" border="0" alt="" />
]]>
闂鏄腑鏂囨暟鎹彁浜ゅ埌action閲岄兘鎴愪簡涔辯爜.
鐢╬ost鎻愪氦鏃?騫朵笉浼氬嚭鐜頒笂闈㈡彁鍒扮殑涔辯爜闂.
璇烽棶璇ユ庢牱瑙e喅鎻愪氦鐢℅ET鎻愪氦鐨勪貢鐮侀棶棰?
struts.xml宸茬粡璁劇疆浜?br />
<constant name="struts.i18n.encoding" value="GBK" />
JSP欏甸潰涔熻緗簡
<%@ page language="java" contentType="text/html; charset=GBK"%>
<s:form action="search.action" method="get">
<input type="hidden" name="order" value="hit">
<table>
<tr>
<td><s:textfield label="涔﹀悕" name="bookName"/></td>
</tr>
<tr>
<td><s:textfield label="浣滆? name="authorName"/></td>
</tr>
<tr>
<td><s:textfield label="鍑虹増紺? name="publishName"/></td>
</tr>
<tr>
<td>
<s:select label="鎶樻墸" list="#{0:'璇烽夋嫨鎶樻墸',1:'30鎶樹互涓?,2:'30鎶樺埌50鎶?,3:'50鎶樺埌70鎶?,4:'70鎶樹互涓?}"
listKey="key" listValue="value">
</s:select>
</td>
</tr>
<tr>
<td align="center"><input type="submit" value="紜畾"></td><td align="center"><input type="reset" value="閲嶆柊濉啓"></td>
</tr>
</table>
</s:form>
鍦⊿earchAction閲岃緭鍑烘煡璇㈡潯浠?姣斿璇村浘涔﹀悕縐?鍦ㄦ帶鍒跺彴閮芥垚浜嗕貢鐮?/span>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transactionManager"></property>
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="userDAO" class="dgut.ke.dao.impl.UserDAO">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="userService" parent="txProxyTemplate" class="dgut.ke.service.impl.UserService">
<property name="userDAO" ref="userDAO" />
</bean>
... ....
鍚姩Tomecat鏃跺嚭浜嗛敊.涔嬪墠娌℃湁娣誨姞浜嬪姟澶勭悊鏃?涓婇潰鐨勪唬鐮佹槸鍙互姝e父榪愯鐨?娣誨姞浜嬪姟涔嬪悗鍗村嚭鐜頒互涓嬮敊璇?br />
ERROR - Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/applicationContext-hibernate.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [dgut.ke.service.impl.UserService]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
Caused by:
org.springframework.beans.NotWritablePropertyException: Invalid property 'transactionManager' of bean class [dgut.ke.service.impl.UserService]: Bean property 'transactionManager' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
瑙e喅鍔炴硶
鎶?br />
<bean id="userService" parent="txProxyTemplate" class="dgut.ke.service.impl.UserService">
<property name="userDAO" ref="userDAO" />
</bean>
鎹㈡垚浠ヤ笅浠g爜灝卞彲浠ユ甯歌繍琛屼簡
<bean id="userService" parent="txProxyTemplate">
<property name="target">
<bean class="dgut.ke.service.impl.UserService">
<property name="userDAO" ref="userDAO"></property>
</bean>
</property>
</bean>
package dgut.ke.interceptors;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import dgut.ke.model.Catalog;
import dgut.ke.model.Publish;
import dgut.ke.model.Subject;
import dgut.ke.service.ICatalogService;
import dgut.ke.service.IPublishService;
import dgut.ke.service.ISubjectService;
public class AddBookInterceptor extends MethodFilterInterceptor {
/**
*
*/
private static final long serialVersionUID = 1135497226250835266L;
private ISubjectService subjectService ;
private ICatalogService catalogService ;
private IPublishService publishService ;
public ICatalogService getCatalogService() {
return catalogService;
}
public IPublishService getPublishService() {
return publishService;
}
public ISubjectService getSubjectService() {
return subjectService;
}
public void setCatalogService(ICatalogService catalogService) {
this.catalogService = catalogService;
}
public void setPublishService(IPublishService publishService) {
this.publishService = publishService;
}
public void setSubjectService(ISubjectService subjectService) {
this.subjectService = subjectService;
}
@Override
protected String doIntercept(ActionInvocation invoation) throws Exception {
// TODO 鑷姩鐢熸垚鏂規硶瀛樻牴
System.out.println("-------- 鎷︽埅鍣ㄥ紑濮嬫墽琛?----------");
List<Subject> subject_list = (ArrayList<Subject>)subjectService.findAll();
List<Catalog> catalog_list = (ArrayList<Catalog>)catalogService.findAll();
List<Publish> pubish_list = (ArrayList<Publish>)publishService.findAll();
//ActionContext act = ActionContext.getContext() ;
ActionContext act = invocation.getInvocationContext() ;
HttpServletRequest request = (HttpServletRequest) act.get(ServletActionContext.HTTP_REQUEST) ;
request.setAttribute("subject_list", subject_list) ;
request.setAttribute("catalog_list", catalog_list) ;
request.setAttribute("publish_list", pubish_list) ;
System.out.println("-------- 鎷︽埅鍣ㄦ墽琛岀粨鏉?----------");
return Action.INPUT;
}
}
涓轟簡瀹炵幇request.setAttribute(String str, Object obj) ;.鏈鍏堟槸璁╀笂闈㈢殑綾誨疄鐜?a title="interface in org.apache.struts2.interceptor" target="classFrame">ServletRequestAware 鎺ュ彛.
浣嗘槸鍦ㄨ繍琛岀殑鏃跺欏嵈鍑虹幇浜嗙┖鎸囬拡寮傚父銆傚悗鏉ユ敼鎴愪互涓婄殑浠g爜灝卞彲浠ユ甯歌繍琛岋紝浣嗘槸榪樻槸
涓嶅お鏄庣櫧
鏇劇粡鍦ㄤ竴鏈功涓婄湅鍒頒竴孌佃瘽錛氭瀯寤篿nterceptor鏈閲嶈鐨勫師鍒欙細interceptor蹇呴』鏄棤鐘舵佺殑錛屽茍涓斾笉鑳?br />
澶熶嬌鐢ㄤ換浣旳ctionInvocation鎻愪緵鑼冨洿浠ュ鐨凙PI