1,ckeditor:
1),http://ckeditor.com/download
CKEditor for Java ;---3.6.2下载;---ckeditor-java-3.6.2.war使用Tomcat分发包;---得到ckeditor-java-3.6.2文件内容;
2),复制ckeditor文件夹到项目web根路径下;
3),复制ckeditor-java-core-3.5.3.jar类库到项目web-inf下。
2,ckfinder:
1),http://ckfinder.com/download
Java;---2.2.1下载;---ckfinder_java_2.2.1.zip解压;---CKFinderJava.war使用Tomcat分发包;---得到CKFinderJava文件;
2),ckfinder
2),复制ckfinder文件夹到项目web根路径下;
3),复制lib下的类库到项目web-inf下(commons-fileupload-1.2.2.jar和commons-io-2.0.1.jar已有,不用复制)。
3,复制CKFinderJava\WEB-INF\config.xml到项目的web-inf下:
Config.xml配置修改:
<enabled>true</enabled>;---开启上传;
<baseURL>/sshWeb/WebsiteBackstage/userfiles/</baseURL>---上传文件存放位置;
上传文件、图片、flash的类型配置(先不动);
4,ckeditor\config.js修改:
CKEDITOR.editorConfig = function( config )
{
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.language = "zh-cn" ;
config.filebrowserWindowWidth = '1000';
config.filebrowserWindowHeight = '700';
config.filebrowserBrowseUrl = '/sshWeb/ckfinder/ckfinder.html' ;
config.filebrowserImageBrowseUrl = '/sshWeb/ckfinder/ckfinder.html?type=Images' ;
config.filebrowserFlashBrowseUrl = '/sshWeb/ckfinder/ckfinder.html?type=Flash' ;
config.filebrowserUploadUrl = '/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Files' ;
config.filebrowserImageUploadUrl = '/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Images' ;
config.filebrowserFlashUploadUrl = '/ckfinder/core/connector/java/connector.java?command=QuickUpload&type=Flash' ;
};
参考文章:
http://www.cnblogs.com/yezhenhan/archive/2011/12/10/2282986.html
----------------------------------------------------------------------------------------------------
5,Js写法的页面代码:
<script src="../../ckeditor/ckeditor.js" type="text/javascript"></script>
<script src="../../ckfinder/ckfinder.js" type="text/javascript"></script>
<script src="../js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../../ckeditor/adapters/jquery.js" type="text/javascript"></script>
<s:form action="about_add">
<s:textfield name="aboutUs.title" label="标题"/>
<s:textarea name="aboutUs.content" rows="30" cols="50" label="内容"/>
<script type="text/javascript">
$('#editor').ckeditor();
var editor = CKEDITOR.replace('aboutUs.content');
CKFinder.setupCKEditor(editor, '/sshWeb/ckfinder/');
</script>
<s:submit/>
</s:form>
6,Web.xml配置:
---struts2与servlet并存解决方法:使用自定义过滤器,将web.xml中添加的ckfinder的servlet过滤内容从struts2过滤中排除;
<filter>
<filter-name>MyServlet</filter-name>
<filter-class>util.ReDispatcherFilter</filter-class>
<init-param>
<param-name>includeServlets</param-name>
<param-value>connector.java</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>MyServlet</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>ConnectorServlet</servlet-name>
<servlet-class>com.ckfinder.connector.ConnectorServlet</servlet-class>
<init-param>
<param-name>XMLConfig</param-name>
<param-value>/WEB-INF/config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ConnectorServlet</servlet-name>
<url-pattern>
/ckfinder/core/connector/java/connector.java
</url-pattern>
</servlet-mapping>
<filter>
<filter-name>FileUploadFilter</filter-name>
<filter-class>com.ckfinder.connector.FileUploadFilter</filter-class>
<init-param>
<param-name>sessionCookieName</param-name>
<param-value>JSESSIONID</param-value>
</init-param>
<init-param>
<param-name>sessionParameterName</param-name>
<param-value>jsessionid</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>FileUploadFilter</filter-name>
<url-pattern>
/ckfinder/core/connector/java/connector.java
</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
7,自定义过滤器:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
public class ReDispatcherFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException
{
HttpServletRequest request = (HttpServletRequest)req;
String target = request.getRequestURI();
target = target.lastIndexOf("?")>0
?target.substring(target.lastIndexOf("/")+1,target.lastIndexOf("?")-target.lastIndexOf("/"))
:target.substring(target.lastIndexOf("/")+1);
System.out.println(target);
if(this.includes.contains(target))
{
RequestDispatcher rdsp = request.getRequestDispatcher(target);
System.out.println("go..............."+rdsp);
rdsp.forward(req, resp);
}
else
chain.doFilter(req, resp);
}
private ArrayList<String> includes = new ArrayList<String>();
public void init(FilterConfig config) throws ServletException {
this.includes.addAll( Arrays.asList(config.getInitParameter("includeServlets").split(",")));
}
}
参考文章:
ssh&ckfinder&ckeditor struts2与servlet并存解决方法
http://blog.csdn.net/databaseyan/article/details/6914654
http://hi.baidu.com/xsl2007/blog/item/4eb796cf94e35f0992457e11.html
///
其它问题:
上传文件中文名问题;
上传文件位置问题;
单纯Ckeditor的使用:
下载最新的ckeditor文件: http://ckeditor.com/download
解压后复制到web层根目录下;
页面引用js:
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>
替换TEXTAREA标签:
<textarea rows="30" cols="50" name="editor01">请输入.</textarea>
<script type="text/javascript">CKEDITOR.replace('editor01');</script>