一、先看效果,再看代码:
1、点击fckeditor插入超链接:
2、上传文件:点击上传成功提示框的确定后,系统会自动跳转
3、跳转到超链接信息页面
4、最终效果:
二、代码修改
1、修改fckeditor里面的fckconfig.js文件
2、修改fckeditor-->>dialog-->>fck_link.html
3、配置struts-config.xml
1
2
4、附件:ScoreUploadExcelForm、LinkUploadAction代码
ScoreUploadExcelForm代码:
/**
* 所要上传的文件的Form
* @author ScoreTechnicalTeam
* @version $Revision: $ $Date: $
*/
public class ScoreUploadExcelForm extends BaseForm implements java.io.Serializable{
private FormFile file; 该file与fck_link.html中的name="file"对应
* 所要上传的文件的Form
* @author ScoreTechnicalTeam
* @version $Revision: $ $Date: $
*/
public class ScoreUploadExcelForm extends BaseForm implements java.io.Serializable{
private FormFile file; 该file与fck_link.html中的name="file"对应
public FormFile getFile() {
return file;
}
return file;
}
public void setFile(FormFile file) {
this.file = file;
}
this.file = file;
}
}
LinkUploadAction代码:
package com.score.web.action.resource.browser;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ResourceBundle;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import com.score.model.base.ScoreUploadExcelForm;
import com.score.web.action.core.BaseAction;
import com.score.web.action.core.BaseAction;
public class LinkUploadAction extends BaseAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(log.isDebugEnabled()) {
log.debug("LinkUploadAction begin...");
}
ScoreUploadExcelForm scoreUploadFileForm = (ScoreUploadExcelForm) form;
FormFile formfile = scoreUploadFileForm.getFile();
String uri = membersHead(request,formfile);
PrintWriter out = response.getWriter();
out.print("") ;此处代码是将链接写入到页面,即效果图第三个步骤
out.flush();
out.close();
if(log.isDebugEnabled()) {
log.debug("LinkUploadAction begin...");
}
return null;
}
public String membersHead(HttpServletRequest request,FormFile file) {
String uri = "";
ResourceBundle rb = ResourceBundle.getBundle("vfsconfig");
// String dir = servlet.getServletContext().getRealPath("/upload");
String dir = rb.getString("vfs.basepath"); 此处是从properties文件中取到的图片上传后绝对路径,可以在spring _service里面配置
// 文件夹
File dirFile = null;
boolean bFile = false;
dirFile = new File(dir);
bFile = dirFile.exists();// true 该文件夹存在,false 不存在
if (bFile == false) {
bFile = dirFile.mkdirs();
if (bFile == false) {
System.out.println(" 文件夹创建失败!");
}
}
if (bFile == true) {
try {
InputStream input = file.getInputStream();// 能从FormFile中获得输入流
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(log.isDebugEnabled()) {
log.debug("LinkUploadAction begin...");
}
ScoreUploadExcelForm scoreUploadFileForm = (ScoreUploadExcelForm) form;
FormFile formfile = scoreUploadFileForm.getFile();
String uri = membersHead(request,formfile);
PrintWriter out = response.getWriter();
out.print("") ;此处代码是将链接写入到页面,即效果图第三个步骤
out.flush();
out.close();
if(log.isDebugEnabled()) {
log.debug("LinkUploadAction begin...");
}
return null;
}
public String membersHead(HttpServletRequest request,FormFile file) {
String uri = "";
ResourceBundle rb = ResourceBundle.getBundle("vfsconfig");
// String dir = servlet.getServletContext().getRealPath("/upload");
String dir = rb.getString("vfs.basepath"); 此处是从properties文件中取到的图片上传后绝对路径,可以在spring _service里面配置
// 文件夹
File dirFile = null;
boolean bFile = false;
dirFile = new File(dir);
bFile = dirFile.exists();// true 该文件夹存在,false 不存在
if (bFile == false) {
bFile = dirFile.mkdirs();
if (bFile == false) {
System.out.println(" 文件夹创建失败!");
}
}
if (bFile == true) {
try {
InputStream input = file.getInputStream();// 能从FormFile中获得输入流
String fileName = file.getFileName();
OutputStream output = new FileOutputStream(dir + "/" + fileName);
int bytesReader = 0;
byte[] readbuffer = new byte[102400];
while ((bytesReader = input.read(readbuffer, 0, 102400)) != -1) {
output.write(readbuffer, 0, bytesReader);
}
output.close();
OutputStream output = new FileOutputStream(dir + "/" + fileName);
int bytesReader = 0;
byte[] readbuffer = new byte[102400];
while ((bytesReader = input.read(readbuffer, 0, 102400)) != -1) {
output.write(readbuffer, 0, bytesReader);
}
output.close();
String webPath = rb.getString("resourceUrl");此处是从properties文件中取到的要上传图片的IP及端口,可以在spring _service里面配置
// 资料路径
uri = webPath +"/linkUpload/"+fileName;
} catch (Exception e) {
e.printStackTrace();
}
}
return uri;
}
}
// 资料路径
uri = webPath +"/linkUpload/"+fileName;
} catch (Exception e) {
e.printStackTrace();
}
}
return uri;
}
}