`
gstarwd
  • 浏览: 1487880 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

fckedit和struts2集成不能上传文件的解决方法

阅读更多

以前在使用fckedit+strut1上传文件很顺利,后来使用了 fckedit+struts2发现附件不能上传了。今天刚刚解决了这个问题,解决办法是使用fckedit2.6版本的就可以了,2.6的版本配置起来 比较简单,在web.xml中不再需要指定taglib,仅需要增加下面的配置:

 

  <servlet>
  <servlet-name>ConnectorServlet</servlet-name>
  <servlet-class>
   net.fckeditor.connector.ConnectorServlet
  </servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>ConnectorServlet</servlet-name>
  <!-- Do not wrap this line otherwise Glassfish will fail to load this file -->
  <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
 </servlet-mapping>

 

从网上下载fckedit2.6 的war包后,把fckedit目录和userfiles目录复制到本地webapps根目录下,另外注意一定要把demo中WEB- INF/classes目录下的fckeditor.properties文件复制过来,如果遗漏这个文件,是会报不能上传文件的错误信息。

 

另外jsp也面中Fckedit标签和以前的不一样,taglib的uri发生变化了,目前 的taglib是这样写的:

 

<%@ taglib uri="http://java.fckeditor.net " prefix="FCK" %>

 

fckedit编辑器的格式:

 

   <FCK:editor instanceName="EditorDefault">
    <jsp:attribute name="value">This is some <strong>sample text
     </strong>. You are using <a href="http://www.fckeditor.net ">
     FCKeditor</a>.
    </jsp:attribute>
   </FCK:editor>

 

注意EditorDefault实际就是id名字,但不可以写成 id="EditorDefault",EditorDefault是自己可随意取的名字。在struts2中,可参考以下格式来展示fckedit的文 本内容:

 

    <FCK:editor instanceName="content"  width="100%" height="400" >
      <jsp:attribute name="value"> <s:property value="editEntity.infContent" escape="false" /></jsp:attribute>
    </FCK:editor>
    <s:hidden name="editEntity.infContent" />

 

下面是openjweb cms内容管理系统信息编辑页面的代码,供参考:

 

<%@page contentType="text/html;charset=UTF-8"%>
<%@ page import="org.openjweb.core.util.DropdownListBoxUtil"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags " %>
<%@ taglib uri="http://java.fckeditor.net " prefix="FCK" %>
 
<html>
<head>
 
<title> 档案鉴定与销毁</title>
<style type="text/css">
<!--
body {
 margin-left: 0px;
 margin-top: 0px;
 margin-right: 0px;
 margin-bottom: 0px;
}
-->
</style>
<link href="<%=request.getContextPath() %>/css/bobona.css" rel="stylesheet" type="text/css" />

 
<script language="JavaScript">

 
  
function editInfo()
{
      var o = FCKeditorAPI.GetInstance('content') ;
   var c = o.GetXHTML();
   document.forms[0].elements['editEntity.infContent'].value = c;
      document.forms[0].submit();
}

function getDictName(dbServiceName,entityClassName,codeFieldName,codeFieldValue,nameField,parmType,obj)
{
   StringUtil.getDictNameByCode(dbServiceName,entityClassName,codeFieldName,codeFieldValue,nameField,parmType,{callback:function(data){setDictName(data,obj)}});
}
function setDictName(data,obj)
{
obj.value=data;

}

function fn_keydown()
{
 
  if(event.keyCode==13){
    event.keyCode=9
 
}
}
</script>
<script type='text/javascript' src='<%=request.getContextPath()%>/js/util.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/js/engine.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/StringUtil.js'></script>
<script language="javascript" type="text/javascript" src="<%=request.getContextPath()%>/My97DatePicker/WdatePicker.js"></script>

</head>
<BODY onkeydown="fn_keydown()" >


<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="1" bgcolor="4B6C95"></td>
  </tr>
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td valign="middle" class="Bd11" bgcolor="#D4D0C8">
                <span class="font3">当前位置: 信息编辑</span></td>
               
     
          </tr>
        </table>
        <br />
</table> 
<s:form name="editForm" method="post" action="listCmsInfo!save.action">
 
 
<table align="center" class="bd2">
  <tr>
    <td height="246" scope="col"><br />
        <table align="center" cellpadding="0" cellspacing="0" class="bd4">
        <FONT COLOR="#0000FF"><s:actionmessage /> </FONT>
        <FONT COLOR="#FF0000"><s:actionerror /> </FONT>
          <tr>
        <td class="bd3" ><table width="100%" border="0" cellspacing="0" cellpadding="0">
       
         <tr>
            <td width="10%" class="mains"><s:text name="CmsInfo.infTitle"/></td>
             <td width="40%" class="maint1"><label>
                     <s:textfield key="CmsInfo.infTitle" name="editEntity.infTitle" theme="simple"    size="50"/>
                </label></td>
                   <td width="10%" class="mains">原文作者</td>
             <td width="40%" class="maint1"><label>
                      <s:textfield theme="simple" name="editEntity.infAuthor"   />
                </label></td>
              
        </tr> 
        <tr>
         <td width="10%" class="mains"><s:text name="CmsInfo.infUrl"/></td>
             <td width="40%" class="maint1" colspan="3"><label>
                     <s:textfield theme="simple" name="editEntity.infUrl" size="50"  />
                </label><font color="#FF0000">&nbsp;&nbsp;(说明:如果引用其他地址,则在此填写URL)</font& gt;</td>
        </tr>
       
   <!--      <tr>
            <td width="10%" class="mains"><s:text name="CmsInfo.isUrl"/></td>
             <td width="40%" class="maint1"><label>
                     <s:select theme="simple"   name="editEntity.isUrl"  list="#request['map'].isUrl" listKey="code" listValue="name" emptyOption="true"   />
   
                </label></td>
                
               
             
        </tr>   
       
            <tr>
            <td width="10%" class="mains"><s:text name="CmsInfo.infClickCount"/></td>
             <td width="40%" class="maint1"><label>
                      <s:textfield theme="simple" name="editEntity.infClickCount"  readonly="true"   cssStyle="color:gray" />
   
                </label></td>
               
                 <td width="10%" class="mains"><s:text name="CmsInfo.isAllowFeedback"/></td>
             <td width="40%" class="maint1"><label>
                     <s:select theme="simple"  name="editEntity.isAllowFeedback"  list="#request['map'].isAllowFeedback" listKey="code" listValue="name" emptyOption="true"   />
   
                </label></td>
        </tr>      -->
       
         <tr>
            <td width="10%" class="mains"><s:text name="CmsInfo.infSource"/></td>
             <td width="40%" class="maint1"><label>
                      <s:textfield theme="simple" name="editEntity.infSource"   />
                </label></td>
               
                 <td width="10%" class="mains"><s:text name="CmsInfo.infKeyword"/></td>
             <td width="40%" class="maint1"><label>
                      <s:textfield theme="simple" name="editEntity.infKeyword"   />
                </label></td>
        </tr> 
    <s:hidden name="editEntity.flowStatus"/>
    <s:hidden name="editEntity.updateUid"/>
    <s:hidden name="editEntity.updateDt"/>
    <s:hidden name="editEntity.sortNo"/>
    <s:hidden name="editEntity.pkId"/>
    <s:hidden name="editEntity.objName"/>
    <s:hidden name="editEntity.dataFlg"/>
    <s:hidden name="editEntity.createUid"/>
    <s:hidden name="editEntity.createDt"/>
    <s:hidden name="editEntity.rowId"/>
    <s:hidden name="editEntity.masterRowId"/>
    <s:hidden name="editEntity.cateTreeCode"/>
    <s:hidden name="masterRowId"/>
    <s:hidden name="selId"/>
    <input type="hidden" name="cateTreeCode" value="${cateTreeCode}"/>
   
     <tr align="center">     
 
     <td height="435" colspan="4">
      <FCK:editor instanceName="content"  width="100%" height="400" >
      <jsp:attribute name="value"> <s:property value="editEntity.infContent" escape="false" /></jsp:attribute>
    </FCK:editor>
    <s:hidden name="editEntity.infContent" />
    </td>
    </tr>
  
 
  
      <tr>
          <td width="10%"   align="center" colspan="4">
                   <input type="button" name="Submit22" value="保存" onclick="editInfo();" style=" color:#000000; font-size:12px; width:61px; height:20px; padding:3px; border:0px;background-image:url(<%=request.getContextPath() %>/images/bt.gif)">
                   <!-- <input type="button" name="Submit222" value="返回" onClick="javascript:history.go(-1);" style=" color:#000000; font-size:12px; width:61px; height:20px; padding:3px; border:0px;background-image:url(<%=request.getContextPath() %>/images/bt.gif)" />
                  -->
                  <input type="button" name="Submit222" value="关闭" onClick="opener.window.location.reload();window.close();" style=" color:#000000; font-size:12px; width:61px; height:20px; padding:3px; border:0px;background-image:url(<%=request.getContextPath() %>/images/bt.gif)" />
                    </td>
  
              </tr>
 
</table>

</s:form>
 
</body>
</html>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics