1.下载FCKeditor_2.6.4.zip,http://downloads.sourceforge.net/project/fckeditor/FCKeditor/2.6.4/FCKeditor_2.6.4.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Ffckeditor%2Ffiles%2FFCKeditor%2F2.6.4%2F&ts=1292413994&use_mirror=cdnetworks-kr-1及相关的java的一个项目demo:fckeditor-java-demo-2.6.war,http://downloads.sourceforge.net/project/fckeditor/FCKeditor.Java/2.6/fckeditor-java-demo-2.6.war?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Ffckeditor%2Ffiles%2FFCKeditor.Java%2F2.6%2F&ts=1292413946&use_mirror=cdnetworks-kr-1
,其实就一个demo就可以了,我是按demo来的。
2,解压fckeditor-java-demo-2.6.war,看里面的东西不多说了,把web.xml里面内容复制到你的项目web.xml里面,还有lib下面的jar包放到项目里面,及classes目录下面的fckeditor.properties放到src目录下,fckeditor目录放到webroot下面。
3,好了,在你的jsp里面直接创建fckeditor对象
- <%
- //创建fckeditor对象,参数request对象,还有inputname
- FCKeditor fckeditor = new FCKeditor(request,"content");
- //默认的工具栏太多了东西,自己建了一个Demo
- fckeditor.setToolbarSet("Demo");
- fckeditor.setWidth("601px");
- fckeditor.setHeight("371px");
- %>
自己有选择的定义ToolbarSet;修改fckeditor下的fckconfig.js,添加下面内容:
- FCKConfig.ToolbarSets["Demo"] = [
- ['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','About'],
- ['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],
- ['TextColor','BGColor'],
- ] ;
4.在需要的地方直接out.println(fckeditor);
- <%out.print(fckeditor); %>
5,如果这样整合struts2时上传图片会出现错误,因为配置的strut拦截器拦截/*,把fckeditor也给拦了,并且在一连串的chain中有些东西丢了,这时呢有两种办法,一种把web.xml里面struts拦截的url /*改为只拦截*.action以及.jsp,这种方法行得通,不过如果咱们整合spring的话action交给spring时咱们可以不用.action那么麻烦,这时就必须让struts拦截/*了,这时有第二种办法解决,及重建一个struts拦截器,当拦截到是fckeditor时直接不用再往下面的chain传了,直接返回就行。
<1>新建一类例如:FckeditorFilter,然后让它继承StrutsPrepareAndExecuteFilter 并且重写doFilter方法.
- @Override
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
- HttpServletRequest request = (HttpServletRequest) req;
- if ("/fckeditor/editor/filemanager/connectors".equals(request.getServletPath())){
- chain.doFilter(req, res);
- }else{
- super.doFilter(req, res, chain);
- }
- }
<2>更改web.xml里面的struts拦截器类为咱们上面新建的就可以了。
6,用js得到fckeditor的内容,代码如下。
- function getText(){
- var oEditor = FCKeditorAPI.GetInstance('content'); //content 为fckeditor的名称
- var content = oEditor.GetXHTML(true);
- return content;}
转载于:https://blog.51cto.com/movedo/456518