锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 榪欎細鎶涘嚭涓涓竴寮傚父,鍥犱負鍦╬arams.get("username")榪斿洖鐨勬槸涓涓瓧絎︿覆鏁扮粍,鎵浠ヤ笉鑳借繖鏍瘋漿鎹?ActionContext聽context聽=聽ActionContext.getContext();
Map聽params聽=聽context.getParameters();
String聽username聽=聽(String) params.get("username");
姝g‘鐨勫仛娉曟槸:
String username = ((String[])params.get("username"))[0];
]]>
----------------------------------------------------------------------------
web.xml<filter>
聽聽聽聽<filter-name>webwork</filter-name>
聽聽聽聽<filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
聽聽聽聽<filter-name>webwork</filter-name>
聽聽聽聽<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
聽聽聽聽<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
榪欓噷浣跨敤浜嗕竴涓狥ilter鏉ュ鎵鏈夌殑url榪涜榪囨護,鑰屽彧鏈夊湪webwork.properties涓殑璁懼畾鐨剋ebwork.action.extension浣滀負鎵╁睍鍚嶆墠浼氳瑙f倝涓轟竴涓猘ction.
鑰屽畾涔変簡涓涓洃鍚櫒涓昏鏄敤Spring鐨勭洃鍚琖eb瀹瑰櫒閲岀殑鍙樺寲,榪欓噷涓昏鏄敤浜嶴pring浣滀負WebWork鐨処oC.濡傛灉鎯寵Spring鏈夊涓猚ontext閰嶇疆鏂囦歡,閭e氨鍙姞鍏ヤ笅闈㈢殑浠g爜:<context-param>
聽聽聽聽<param-name>contextConfigLocation</param-name>
聽聽聽聽<param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>
</context-param>
榪欓噷濡傛灉鎯沖畾涔変竴涓猈ebWork tag,閭d箞灝卞彲鍔犲叆浠ヤ笅鐨勪唬鐮?<taglib>
聽聽聽聽<taglib-uri>webwork</taglib-uri>
聽聽聽聽<taglib-location>/WEB-INF/lib/webworkxx.jar</taglib-location>
</taglib>
--------------------------------------------------------------------------------
鍦ㄨxwork.xml涔嬪墠,鎴戜滑鍏堜簡瑙ebwork-default.xml鏂囦歡,榪欎釜鏂囦歡鏄敱webwork.jar鏂囦歡閲屾湁鐨?瀛樻斁鍦╟lasspath涓?鎵浠ユ垜浠笉鐢ㄥ垱寤鴻繖涓枃浠?鍥犱負姣忔榪愯webwork搴旂敤鏃?webwork閮戒細鑷姩鍘籧lasspath鏌ユ壘榪欎釜鏂囦歡.榪欎釜鏂囦歡棰勫厛璁劇疆濂戒簡涓浜涢粯璁ょ殑鍙傛暟,姣斿result type, interceptors絳?鍙互璇存槸鎴戜滑xwork.xml涓殑榛樿鍊?鍚屾椂涔熶負鎴戜滑鐨剎work.xml鎻愪緵濂戒簡寰堝宸ュ叿,姣斿params鎷︽埅鍣ㄥ氨鏄渶鍏稿瀷鐨勪竴涓?
鍦ㄧ紪鍐檟work.xml鏃?鎴戜滑涓鑸兘瑕佸鍏ヨ繖涓獁ebwork-default.xml鏂囦歡,浠g爜濡備笅:<include聽file="webwork-default.xml"/>
鍏蜂綋鐨剎work.xml閰嶇疆,鐢變互鍚庣殑瀛︿範涓粰鍑?..(鍛?...鎴戜篃榪樹笉娓呮,娌℃湁瀹炶返榪囧憿..)
xwork.xml鏂囦歡蹇呴』鏀懼湪/WEB-INF/classes/涓?
--------------------------------------------------------------------------------
涓嬮潰璇翠竴涓媤ebwork.properties鏂囦歡,榪欎釜鏂囦歡鏄厤緗畐ebwork琛屼負鐗規х殑鏂囦歡,浠栧彲浠ユ敼鍙榳ebwork鐨勬墿灞曞悕,浠ュ強緙栫爜絳?榪欎釜鏂囦歡鐨勮緇嗚鏄庡彲浠ュ弬鑰冨畼鏂圭殑鏂囨。:###聽Webwork聽default聽properties
###(can聽be聽overridden聽by聽a聽webwork.properties聽file聽in聽the聽root聽of聽the聽classpath)
###
###聽Specifies聽the聽Configuration聽used聽to聽configure聽webwork
###聽one聽could聽extend聽com.opensymphony.webwork.config.Configuration
###聽to聽build聽one's聽customize聽way聽of聽getting聽the聽configurations聽parameters聽into聽webwork
#聽webwork.configuration=com.opensymphony.webwork.config.DefaultConfiguration
###聽This聽can聽be聽used聽to聽set聽your聽default聽locale聽and聽encoding聽scheme
#聽webwork.locale=en_US
webwork.i18n.encoding=UTF-8
###聽if聽specified,聽the聽default聽object聽factory聽can聽be聽overridden聽here
###聽Note:聽short-hand聽notation聽is聽supported聽in聽some聽cases,聽such聽as聽"spring"
###聽聽聽聽聽聽聽Alternatively,聽you聽can聽provide聽a聽com.opensymphony.xwork.ObjectFactory聽subclass聽name聽here
#聽webwork.objectFactory聽=聽spring
###聽specifies聽the聽autoWiring聽logic聽when聽using聽the聽SpringObjectFactory.
###聽valid聽values聽are:聽name,聽type,聽auto,聽and聽constructor聽(name聽is聽the聽default)
webwork.objectFactory.spring.autoWire聽=聽name
###聽Parser聽to聽handle聽HTTP聽POST聽requests,聽encoded聽using聽the聽MIME-type聽multipart/form-data
#聽webwork.multipart.parser=cos
#聽webwork.multipart.parser=pell
webwork.multipart.parser=jakarta
#聽uses聽javax.servlet.context.tempdir聽by聽default
webwork.multipart.saveDir=
webwork.multipart.maxSize=2097152
###聽Load聽custom聽property聽files聽(does聽not聽override聽webwork.properties!)
#聽webwork.custom.properties=application,com/webwork/extension/custom
###聽How聽request聽URLs聽are聽mapped聽to聽and聽from聽actions
webwork.mapper.class=com.opensymphony.webwork.dispatcher.mapper.DefaultActionMapper
###聽Used聽by聽the聽DefaultActionMapper
webwork.action.extension=action
###聽use聽alternative聽syntax聽that聽requires聽%{}聽in聽most聽places
###聽to聽evaluate聽expressions聽for聽String聽attributes聽for聽tags
webwork.tag.altSyntax=true
###聽when聽set聽to聽true,聽WebWork聽will聽act聽much聽more聽friendly聽for聽developers.聽This
###聽includes:
###聽-聽webwork.i18n.reload聽=聽true
###聽-聽webwork.configuration.xml.reload聽=聽true
###聽-聽raising聽various聽debug聽or聽ignorable聽problems聽to聽errors
###聽聽聽For聽example:聽normally聽a聽request聽to聽foo.action?someUnknownField=true聽should
###聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽be聽ignored聽(given聽that聽any聽value聽can聽come聽from聽the聽web聽and聽it
###聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽should聽not聽be聽trusted).聽However,聽during聽development,聽it聽may聽be
###聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽useful聽to聽know聽when聽these聽errors聽are聽happening聽and聽be聽told聽of
###聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽them聽right聽away.
webwork.devMode聽=聽false
###聽when聽set聽to聽true,聽resource聽bundles聽will聽be聽reloaded聽on聽_every_聽request.
###聽this聽is聽good聽during聽development,聽but聽should聽never聽be聽used聽in聽production
webwork.i18n.reload=false
###聽Standard聽UI聽theme
###聽Change聽this聽to聽reflect聽which聽path聽should聽be聽used聽for聽JSP聽control聽tag聽templates聽by聽default
webwork.ui.theme=xhtml
webwork.ui.templateDir=template
#sets聽the聽default聽template聽type.聽Either聽ftl,聽vm,聽or聽jsp
webwork.ui.templateSuffix=ftl
###聽Configuration聽reloading
###聽This聽will聽cause聽the聽configuration聽to聽reload聽xwork.xml聽when聽it聽is聽changed
webwork.configuration.xml.reload=false
###聽Location聽of聽velocity.properties聽file.聽聽defaults聽to聽velocity.properties
#聽webwork.velocity.configfile聽=聽velocity.properties
###聽Comma聽separated聽list聽of聽VelocityContext聽classnames聽to聽chain聽to聽the聽WebWorkVelocityContext
#聽webwork.velocity.contexts聽=
###聽used聽to聽build聽URLs,聽such聽as聽the聽UrlTag
webwork.url.http.port聽=聽80
webwork.url.https.port聽=聽443
###聽Load聽custom聽default聽resource聽bundles
#聽webwork.custom.i18n.resources=testmessages,testmessages2
###聽workaround聽for聽some聽app聽servers聽that聽don't聽handle聽HttpServletRequest.getParameterMap()
###聽often聽used聽for聽WebLogic,聽Orion,聽and聽OC4J
webwork.dispatcher.parametersWorkaround聽=聽false
###聽configure聽the聽Freemarker聽Manager聽class聽to聽be聽used
###聽Allows聽user聽to聽plug-in聽customised聽Freemarker聽Manager聽if聽necessary
###聽MUST聽extends聽off聽com.opensymphony.webwork.views.freemarker.FreemarkerManager
#webwork.freemarker.manager.classname=com.opensymphony.webwork.views.freemarker.FreemarkerManager
###聽See聽the聽WebWorkBeanWrapper聽javadocs聽for聽more聽information
webwork.freemarker.wrapper.altMap=true
濂?澶ц嚦涓婂凡緇忔竻妤氫簡榪欎簺鏂囦歡鐨勫ぇ鑷崇敤閫?涓嬩竴姝?寮勬竻xwork鐨勯厤緗?
]]>
WebWork2.2鍜學ebWork2.1鍦ㄩ厤緗笂鏈変竴浜涘尯鍒紝鐜板湪鎶奧ebWork2.2鐨勪竴浜涢厤緗斁榪涙潵銆?br />
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">
聽聽聽聽<filter>
聽聽聽聽聽聽聽聽<filter-name>webwork</filter-name>
聽聽聽聽聽聽聽聽<filter-class>com.opensymphony.webwork.dispatcher.FilterDispatcher</filter-class>
聽聽聽聽</filter>
聽聽聽聽<filter-mapping>
聽聽聽聽聽聽聽聽<filter-name>webwork</filter-name>
聽聽聽聽聽聽聽聽<url-pattern>/*</url-pattern>
聽聽聽聽</filter-mapping>
聽聽聽聽<listener>
聽聽聽聽聽聽聽聽<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
聽聽聽聽</listener>
</web-app>
xwork.xml<?xml聽version="1.0"聽encoding="UTF-8"?>
<!DOCTYPE聽xwork聽PUBLIC聽"-//OpenSymphony聽Group//XWork聽1.1.1//EN"
"http://www.opensymphony.com/xwork/xwork-1.1.1.dtd">
<xwork>
聽聽聽聽<!--聽Include聽webwork聽defaults聽(from聽WebWork聽JAR).聽-->
聽聽聽聽<include聽file="webwork-default.xml"聽/>
聽聽聽聽<!--聽Configuration聽for聽the聽default聽package.聽-->
聽聽聽<package聽name="default"聽extends="webwork-default">
聽聽聽聽聽<!--聽Include聽webwork聽defaults聽(from聽WebWork聽JAR).聽-->
聽聽聽聽聽<default-interceptor-ref聽name="completeStack"/>
聽聽聽聽聽聽<action聽name="helloWorld"
聽聽聽聽聽聽聽聽聽class="org.javadream.webwork.ch01.HelloWorld">
聽聽聽聽聽聽聽聽聽<result聽name="success">hello.jsp</result>
聽聽聽聽聽聽</action>
聽聽聽</package>
</xwork>
webwork.propertieswebwork.locale=zh_CN
webwork.i18n.encoding=GB2312
webwork.objectFactory=spring
榪欓噷涓枃鏈夐棶棰橈紝蹇呴』瑕佸湪webwork.properties涓繘鍏ヨ緗?webwork.objectFactory=spring鏄敤spring浣滀負榛樿鐨処oC瀹瑰櫒銆?br />
緙栧啓涓涓狝ction:package聽org.javadream.webwork.ch01;
import聽com.opensymphony.xwork.Action;
import聽java.text.DateFormat;
import聽java.util.*;
public聽class聽HelloWorld聽implements聽Action聽
{
private聽String聽message;
聽public聽String聽execute()聽
{
聽聽聽message聽=聽"Hello,聽WebWorld!,浣犲ソ,Web涓栫晫\n";
聽聽聽message聽+=聽"The聽time聽is:\n";
聽聽聽message聽+=聽DateFormat.getDateInstance().format(new聽Date());;
聽聽聽
聽聽聽//message聽=聽message.replaceAll("\n",聽"<br>");
聽聽聽return聽SUCCESS;
聽}
聽public聽String聽getMessage()聽
{
聽聽聽return聽message;
聽}
}
緙栧啓涓涓鍥緅sp鏂囦歡:<%@聽page聽language="java"聽contentType="text/html;聽charset=gb2312"聽pageEncoding="gb2312"%>
<%@聽taglib聽prefix="ww"聽uri="/webwork"%>
<html>
聽聽聽聽<head>
聽聽聽聽聽聽聽聽<title>Hello聽Page</title>
聽聽聽聽</head>
聽聽聽聽<body>
聽聽聽聽聽聽聽聽The聽message聽generated聽by聽my聽first聽action聽is:
聽聽聽聽聽聽聽聽<br>
聽聽聽聽聽聽聽聽<font聽color="red"><ww:property聽value="message"聽/></font>
聽聽聽聽</body>
</html>
榪欓噷瑕佹敞鎰忥紝<%@ taglib prefix="ww" uri="/webwork"%>蹇呴』瑕佺敤uri="/webwork"錛屽洜涓鴻璁╀粬鍦╳ebwork.jar涓煡鎵緒ebwork.tld錛屽洜涓烘垜浠湪web.xml騫舵病鏈夊畾涔夎繖涓?webwork"榪欎釜uri銆?br />
]]>
Java Servlet娌℃湁浠庢牴鏈笂鏀寔緗戠粶鏂囦歡涓婁紶,榪欐槸涓涓瀬涓嶅ソ鐨勪篃鏋佷笉鐖界殑浜嬫儏.
浠庤屽氨寤剁敓浜哻ommonsUpload鍜宑os榪欎簺涓滀笢綾誨簱,鍛?....榪樼畻濂?涔熷ソ鐢?涓嶈繃娌′粩緇嗗幓鐮旂┒浠栦滑鐨勫疄鐜頒唬鐮?鐢ㄨ搗鏉ユ繪槸蹇冨ぇ蹇冨皬鐨?
涔熸鍥犱負榪欐牱澶氱殑絎笁鏂圭被搴?澶у鐨勬帴鍙i兘涓嶅悓,浠庤屼篃灝卞嚭鐜頒簡璁㏒ervice灞傛棤鎵閫備粠鐨勬劅瑙?鍥犱負涓嶈鏄粠Struts榪樻槸浠嶹ebWork鎴栬呬粠鏈綆鍗曠殑cos榪欎簺綾誨簱寰楀埌鐨勬帴鍙i兘鏄竴縐嶅叿浣撳疄鐜?娌℃湁緇熶竴鐨勬帴鍙?濡傛灉Service灞備笌鏌愪竴縐嶅叿浣撳疄鐜扮浉鍏寵仈,鍒欏繀鐒朵笌榪欑鍏蜂綋瀹炵幇鐨勬鏋舵垨鑰呯被搴撶‖緙栫爜緇戝畾,浠ュ悗灝變笉濂界敤鍏跺畠綾誨簱浜?榪欐槸涓嶅ソ鐨勮璁?鐪熺殑,涓鐐圭伒媧誨害閮芥病鏈?
鑳戒笉鑳借繖鏍峰憿?鍦⊿ervice瀹氫箟涓涓猆ploadFile鎺ュ彛,鎵鏈塖ervice灞傛帴鍙楃殑鍙槸UploadFile鐨勫疄鐜扮被鐨勫疄渚?浠庤岀粺涓浜嗘墍鏈塖ervice鐨勮皟鐢?鑰屼笖涔熶嬌Service鍙互鍦ㄥ悇縐峂VC鎴栬呯涓夋柟綾誨簱涓縼縐?
榪欓噷鐢ㄥ埌浜嗕竴涓璁℃ā寮?閫傞厤鍣ㄦā寮?
浠g爜濡備笅:
姣斿榪欓噷鏈変竴涓叿浣撳疄鐜?
浣犱篃鍙互鍐檆ommonsupload鎴栬卌os鐨勫疄鐜?Service鎺ュ彈鐨勫弬鏁版槸UploadFile鎺ュ彛鐨?鎵浠ヤ綘蹇呴』瀹炵幇UploadFile鎺ュ彛鎵嶈兘浣跨敤Service灞傜殑鍔熻兘.
(鍚庤瘽:鐪嬫潵瀛︿範璁捐妯″紡榪樻槸寰堟湁鐢ㄥ鐨?
褰撲篃瑕佹姏寮冮偅浜涘師鏉hp緋葷粺閲屼笉濂界殑璁捐鍜屾柟娉?
鏂扮殑Java瀹炵幇浼氱敤鍒頒粈涔堟妧鏈憿?
Spring + Hibernate + WW + Ajax
寮鍙戞椂闂?1騫?浠?006騫?鏈?0鍙峰紑濮?
娉ㄦ剰鐨勫湴鏂?
涓嶈鎬ョ潃鍐欎唬鐮?瑕佸厛鍋氬ソ闇姹傚垎鏋愬拰璁捐
娉ㄦ剰鎵╁睍鎬у拰瀵圭紪紼嬫ā寮忕殑鏇村ソ搴旂敤.
鎵撶畻寮婧愯欏圭洰.