先說(shuō)怎么做,再稍微解釋一下為什么這么做
1.webwork.properties里面設(shè)置
webwork.serve.static=false
webwork.multipart.parser=cos
2.在webapp的根目錄下建一個(gè)文件夾webwork,把webwork.jar里面的/com/opensymphony/webwork/static和/template里面的文件和復(fù)制到自己建的webwork文件夾里面,在/webwork/richtexteditor里面建文件夾data(可能會(huì)自動(dòng)建,沒(méi)測(cè)試過(guò))
3.寫一個(gè)RichtexteditorConnector
package?test;

import?java.io.FileFilter;
import?java.io.IOException;
import?java.util.ArrayList;
import?java.util.List;

import?javax.servlet.ServletContext;

import?org.apache.commons.logging.Log;
import?org.apache.commons.logging.LogFactory;

import?com.opensymphony.webwork.components.DefaultRichtexteditorConnector;


public?class?RichtexteditorConnector?extends?DefaultRichtexteditorConnector?{
????
public?static?final?Log?_log?=?LogFactory
????????????.getLog(RichtexteditorConnector.
class);

????
private?ServletContext?servletContext;

????
public?void?setServletContext(ServletContext?servletContext)?{
????????
this.servletContext?=?servletContext;
????}

????
protected?String?calculateActualServerPath(String?actualServerPath,
????????????String?type,?String?folderPath)?
throws?Exception?{
????????String?path?
=?servletContext.getRealPath(actualServerPath);
????????path?
=?path.replace('\\',?'/');
????????makeDirIfNotExists(path);
????????path?
=?path.endsWith("/")???path?:?path?+?"/";
????????
return?path?+?type?+?folderPath;
????}

????
protected?Folder[]?getFolders(String?virtualFolderPath,?String?type)
????????????
throws?Exception?{
????????String?path?
=?calculateActualServerPath(getActualServerPath(),?type,
????????????????virtualFolderPath);
????????makeDirIfNotExists(path);
????????java.io.File?f?
=?new?java.io.File(path);
????????java.io.File[]?children?
=?f.listFiles(new?FileFilter()?{
????????????
public?boolean?accept(java.io.File?pathname)?{
????????????????
if?(!pathname.isFile())?{
????????????????????
return?true;
????????????????}
????????????????
return?false;
????????????}
????????});

????????List?tmpFolders?
=?new?ArrayList();
????????
for?(int?a?=?0;?a?<?children.length;?a++)?{
????????????tmpFolders.add(
new?Folder(children[a].getName()));
????????}

????????
return?(Folder[])?tmpFolders.toArray(new?Folder[0]);
????}

????
protected?FoldersAndFiles?getFoldersAndFiles(String?virtualFolderPath,
????????????String?type)?
throws?Exception?{
????????String?path?
=?calculateActualServerPath(getActualServerPath(),?type,
????????????????virtualFolderPath);
????????makeDirIfNotExists(path);
????????java.io.File?f?
=?new?java.io.File(path);
????????java.io.File[]?children?
=?f.listFiles();

????????List?directories?
=?new?ArrayList();
????????List?files?
=?new?ArrayList();
????????
for?(int?a?=?0;?a?<?children.length;?a++)?{
????????????
if?(children[a].isDirectory())?{
????????????????directories.add(
new?Folder(children[a].getName()));
????????????}?
else?{
????????????????
try?{
????????????????????files.add(
new?File(children[a].getName(),
????????????????????????????fileSizeInKBytes(children[a])));
????????????????}?
catch?(Exception?e)?{
????????????????????_log.error(
"cannot?deal?with?file?"?+?children[a],?e);
????????????????}
????????????}
????????}

????????
return?new?FoldersAndFiles((Folder[])?directories
????????????????.toArray(
new?Folder[0]),?(File[])?files.toArray(new?File[0]));
????}

????
protected?FileUploadResult?fileUpload(String?virtualFolderPath,
????????????String?type,?String?filename,?String?contentType,
????????????java.io.File?newFile)?{
????????
try?{
????????????String?tmpDir?
=?calculateActualServerPath(getActualServerPath(),
????????????????????type,?virtualFolderPath);
????????????makeDirIfNotExists(tmpDir);
????????????String?tmpFile?
=?tmpDir?+?filename;
????????????
if?(makeFileIfNotExists(tmpFile))?{
????????????????
//?already?exists
????????????????int?a?=?0;
????????????????String?ext?
=?String.valueOf(a);
????????????????tmpFile?
=?calculateActualServerPath(getActualServerPath(),
????????????????????????type,?virtualFolderPath)
????????????????????????
+?filename?+?ext;
????????????????
while?(makeFileIfNotExists(tmpFile))?{
????????????????????a?
=?a?+?1;
????????????????????ext?
=?String.valueOf(a);
????????????????????
if?(a?>?100)?{
????????????????????????
return?FileUploadResult.invalidFile();
????????????????????}
????????????????}
????????????????copyFile(newFile,?
new?java.io.File(tmpFile));
????????????????
return?FileUploadResult
????????????????????????.uploadCompleteWithFilenamChanged(filename?
+?ext);
????????????}?
else?{
????????????????copyFile(newFile,?
new?java.io.File(tmpFile));
????????????????
return?FileUploadResult.uploadComplete();
????????????}
????????}?
catch?(Exception?e)?{
????????????_log.error(e.toString(),?e);
????????????e.printStackTrace();
????????????
return?FileUploadResult.invalidFile();
????????}
????}

????
protected?void?unknownCommand(String?command,?String?virtualFolderPath,
????????????String?type,?String?filename,?String?contentType,
????????????java.io.File?newFile)?{
????????
throw?new?RuntimeException("unknown?command?"?+?command);
????}

????
/**
?????*?
?????*?
@param?path
?????*?
@return?true?if?file?already?exists,?false?otherwise.
?????
*/
????
protected?boolean?makeDirIfNotExists(String?path)?{
????????java.io.File?dir?
=?new?java.io.File(path);
????????
if?(!dir.exists())?{
????????????_log.debug(
"make?directory?"?+?dir);
????????????
boolean?ok?=?dir.mkdirs();
????????????
if?(!ok)?{
????????????????
throw?new?RuntimeException("cannot?make?directory?"?+?dir);
????????????}
????????????
return?false;
????????}
????????
return?true;
????}

????
protected?boolean?makeFileIfNotExists(String?filePath)?throws?IOException?{
????????java.io.File?f?
=?new?java.io.File(filePath);
????????
if?(!f.exists())?{
????????????_log.debug(
"creating?file?"?+?filePath);
????????????
boolean?ok?=?f.createNewFile();
????????????
if?(!ok)?{
????????????????
throw?new?RuntimeException("cannot?create?file?"?+?filePath);
????????????}
????????????
return?false;
????????}
????????
return?true;
????}

}
4.xwork.xml加上
<package?name="richtexteditor-browse"?extends="webwork-default"
????????namespace
="/webwork/richtexteditor/editor/filemanager/browser/default/connectors/jsp">
????????
<action?name="connector"
????????????class
="test.RichtexteditorConnector"
????????????method
="browse">
????????????
<param?name="actualServerPath">
????????????????/webwork/richtexteditor/data
????????????
</param>
????????????
<result?name="getFolders"?type="richtexteditorGetFolders"?/>
????????????
<result?name="getFoldersAndFiles"
????????????????type
="richtexteditorGetFoldersAndFiles"?/>
????????????
<result?name="createFolder"
????????????????type
="richtexteditorCreateFolder"?/>
????????????
<result?name="fileUpload"?type="richtexteditorFileUpload"?/>
????????
</action>
</package>
<package?name="richtexteditor-upload"?extends="webwork-default"
????????namespace
="/webwork/richtexteditor/editor/filemanager/upload">
????????
<action?name="uploader"
????????????class
="test.RichtexteditorConnector"
????????????method
="upload">
????????????
<param?name="actualServerPath">
????????????????/webwork/richtexteditor/data
????????????
</param>
????????????
<result?name="richtexteditorFileUpload"?/>
????????
</action>
</package>
5.配置標(biāo)簽
<ww:form action="test" method="post">
?? ?<%request.setAttribute("contextPath",request.getContextPath());%>
?? ?<ww:richtexteditor basePath="%{#request.contextPath}/webwork/richtexteditor/"?? ????? toolbarCanCollapse="false" width="700" label="description" name="content" defaultLanguage="zh-cn" />
?? ?<ww:submit value="submit" />
</ww:form>
6.服務(wù)器端口設(shè)置為80

原因
1.
webwork.serve.static=false
/webwork/*這樣的URL是可以直接訪問(wèn)不需要通過(guò)webwork,這樣做是為了自己可以在里面建文件,并且可以方便的訪問(wèn)這些文件
webwork.multipart.parser=cos
設(shè)置為jakarta上傳文件不成功,com.opensymphony.webwork.interceptor.FileUploadInterceptor解析MultiPartRequestWrapper不成功,原因不清楚,反正用cos就可以了,記得加上cos.jar
2.因?yàn)樵O(shè)置了webwork.serve.static=false需要這樣做
3.覆蓋webwork的DefaultRichtexteditorConnector,最關(guān)鍵的是覆蓋calculateActualServerPath()方法,默認(rèn)是把文件放到/WEB-INF/classes/com/opensymphony/webwork/static/richtexteditor/data/,我們需要放到/webwork/richtexteditor/data/里面,覆蓋其他方法是因?yàn)槟J(rèn)對(duì)文件的訪問(wèn)都是通過(guò)
new File(new URI("file://"+filePath);來(lái)訪問(wèn)的,會(huì)有些問(wèn)題,直接new File(filePath)就可以了
4.使用自己的RichtexteditorConnector,并且設(shè)置參數(shù)actualServerPath,其他參數(shù)不要改,webwork默認(rèn)的是這樣
5.basePath必須自己指定不能用默認(rèn)的,雖然指定的值和默認(rèn)的是一樣,但是不自己指定的話它自動(dòng)加上jsessionid,如/webwork/richtexteditor/;jsessionid=301gs94034pki/editor/fckeditor.html,因?yàn)樵O(shè)置了webwork.serve.static=false,所以服務(wù)器不能解析這個(gè)url
defaultLanguage="zh-cn",不指定的話中文默認(rèn)是繁體
6.服務(wù)器端口必須為80不能為8080,因?yàn)閒ckeditor鏈接你上傳的文件的時(shí)候,不會(huì)把端口加上去