使用ckeditor struts2 freemaker的图片上传Word格式文档下载.docx
《使用ckeditor struts2 freemaker的图片上传Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《使用ckeditor struts2 freemaker的图片上传Word格式文档下载.docx(18页珍藏版)》请在冰豆网上搜索。
stylesheet"
text/css"
href="
ckeditor/contents.css"
/>
8.
style
9.
*
{
10.
font-family:
宋体"
;
11.
font-size:
14px
12.
}
13.
/style>
14.
15.<
title>
CKEditor
Testing<
/title>
16.<
/head>
17.<
body>
18.
19.
form
id="
form1"
name="
method="
post"
action="
ck"
20.
table
width="
650"
height="
400"
border="
0"
align="
center"
21.
tr>
22.
23.
td>
textarea
cols="
80"
content"
/textarea>
24.
25.
CKEDITOR.replace('
content'
addUploadButton(this));
26.
27.
function
addUploadButton(editor)
{
28.
CKEDITOR.on('
dialogDefinition'
function(
ev
){
29.
var
dialogName
=
ev.data.name;
30.
dialogDefinition
ev.data.definition;
31.
if
(
==
'
image'
32.
infoTab
dialogDefinition.getContents(
info'
);
33.
infoTab.add({
34.
type
:
button'
35.
id
upload_image'
36.
align
center'
37.
label
上传'
38.
onClick
evt
39.
thisthisDialog
this.getDialog();
40.
txtUrlObj
thisDialog.getContentElement('
txtUrl'
41.
txtUrlId
txtUrlObj.getInputElement().$.id;
42.
43.
addUploadImage(txtUrlId);
44.
}
45.
},
browse'
//place
front
of
the
browser
button
46.
47.
});
48.
49.
50.
51.
addUploadImage(theURLElementId)
52.
//var
uploadUrl
uploadFiles.jsp"
53.
imgUrl
window.open('
uploadFiles.jsp'
'
_blank'
54.
window.showModalDialog("
55.
alert(imgUrl);
56.
urlObj
document.getElementById(theURLElementId);
57.
//
urlObj.value
imgUrl;
58.
urlObj.fireEvent("
onchange"
59.
60.
61.
/td>
62.
/tr>
63.
64.
65.
input
submit"
Submit"
value="
提交"
66.
reset"
Reset"
重置"
67.
68.
/table>
69.
/form>
70.
71.<
/body>
72.<
/html>
DOCTYPEhtmlPUBLIC"
-//W3C//DTDHTML4.01Transitional//EN"
"
metahttp-equiv="
content="
charset=UTF-8"
scripttype="
src="
<
linkrel="
type="
href="
styletype="
*{
font-family:
font-size:
14px
}
CKEditorTesting<
formid="
name="
method="
action="
tablewidth="
height="
border="
align="
textareacols="
id="
CKEDITOR.replace('
functionaddUploadButton(editor){
CKEDITOR.on('
function(ev){
vardialogName=ev.data.name;
vardialogDefinition=ev.data.definition;
if(dialogName=='
){
varinfoTab=dialogDefinition.getContents('
);
infoTab.add({
type:
'
id:
align:
label:
onClick:
function(evt){
varthisDialog=this.getDialog();
vartxtUrlObj=thisDialog.getContentElement('
'
vartxtUrlId=txtUrlObj.getInputElement().$.id;
addUploadImage(txtUrlId);
}
},'
//placefrontofthebrowserbutton
});
functionaddUploadImage(theURLElementId){
//varuploadUrl="
//varimgUrl=window.open('
varimgUrl=window.showModalDialog("
alert(imgUrl);
//varurlObj=document.getElementById(theURLElementId);
//urlObj.value=imgUrl;
//urlObj.fireEvent("
}
inputtype="
value="
/>
再写struts.xml文件:
Xml代码
?
xml
version="
1.0"
encoding="
UTF-8"
struts
PUBLIC
3.
-//Apache
Software
Foundation//DTD
Struts
Configuration
2.0//EN"
4.
//struts.apache.org/dtds/struts-2.0.dtd"
struts>
--
constant
struts.devMode"
true"
-->
package
index"
extends="
struts-default"
action
class="
com.lee.action.CKAction"
result
success"
freemarker"
freemarker/ck.ftl<
/result>
/action>
15.
16.
name
="
fileUpload"
class
com.lee.action.MyUploadAction"
17.
interceptor-ref
fileUploadStack"
/testStrutsView.jsp
/result
/action
com.lee.action.MyUploadAction2"
uploadFiles.jsp
/package>
29.<
/struts>
xmlversion="
encoding="
?
DOCTYPEstrutsPUBLIC
-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
<
--
constantname="
-->
packagename="
extends="
actionname="
class="
>
resultname="
actionname="
class="
interceptor-refname="
resultname="
/testStrutsView.jsp<
/result>
/action>
uploadFiles.jsp<
写Action类:
Java代码
1.package
com.lee.action;
2.
3.import
java.io.BufferedInputStream;
4.import
java.io.BufferedOutputStream;
5.import
java.io.File;
6.import
java.io.FileInputStream;
7.import
java.io.FileOutputStream;
8.import
java.io.InputStream;
9.import
java.io.OutputStream;
10.import
java.util.Date;
12.import
javax.servlet.http.HttpServletRequest;
14.import
org.apache.struts2.ServletActionContext;
16.import
com.opensymphony.xwork2.Action;
17.import
com.opensymphony.xwork2.ActionSupport;
19.public
MyUploadAction2
extends
ActionSupport
private
static
final
long
serialVersionUID
572146812454l
int
BUFFER_SIZE
16
1024
File
myFile;
String
contentType;
fileName;
imageFileName;
pagePath;
public
getPagePath()
return
void
setPagePath(String
pagePath)
this.pagePath
setMyFileContentType(String
contentType)
this
.contentType
setMyFileFileName(String
fileName)
.fileName
setMyFile(File
myFile)
.myFile
getImageFileName()
copy(File
src,File
dst)
try
InputStream
in
null
OutputStream
out
new
BufferedInputStream(
FileInputStream(src),
BUFFER_SIZE);
BufferedOutputStream(
FileOutputStream(dst),
byte
[]
buffer
[BUFFER_SIZE];
while
(in.re