请教一下关于kindeditor与ASP后台整合,如何取到值提交数据库保存,帮忙改一下新手一个。全部分给你。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请教一下关于kindeditor与ASP后台整合,如何取到值提交数据库保存,帮忙改一下新手一个。全部分给你。相关的知识,希望对你有一定的参考价值。

Newsadd.asp 页面文件名
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="Style.css" type=text/css rel=stylesheet>
<title>添加文章</title>
<link href="editor/themes/default/default.css" rel="stylesheet" />
<script src="editor/kindeditor-all-min.js"></script>
<script src="editor/lang/zh-CN.js"></script>
<script>
KindEditor.ready(function(K)
window.editor = K.create('#editor_id');
);
</script>
<body topmargin="0">

<table border="1" cellspacing="0" width="100%" cellpadding="0"bordercolor="1" style="border-collapse: collapse">
<form name="form1" method="post" action="NewsSave.asp" OnSubmit="return checkdata()" onReset="return ResetForm();">

<tr>
<td align="right" class="unnamed2" valign="middle" bgcolor="#FFFFFF">文章标题:</td>
<td bgcolor="#FFFFFF"> <span style='cursor:hand' title='缩短对话框' onClick='if (me.size>10)me.size=me.size-2'>-</span>
<input name="title" id=me type="TEXT" size=60 maxlength=100 value="试用信息中"style="background-color:ffffff;border: 1 double" onMouseOver="window.status='在这里输入要添加的文章标题,必填';return true;" onMouseOut="window.status='';return true;" >

</td>
</tr>
<tr>
<td align="right" valign="top" class="unnamed2" bgcolor="#FFFFFF" height="145">文章内容:<br><font color="#FF0000">*</font><br><br><br><br><br><br><br><br><br><br>换行请按Shift+Enter<br><br>另起一段请按Enter</td>
<td valign="top">
<textarea id="editor_id" name="content" cols="100" rows="8" style="width:800px;height:400px;visibility:hidden;"></textarea>
</td>
</tr>

<tr align="center">
<td colspan="2" height="25" width="100%" clacc="TDtop">
<input type="button" value=" 返 回 " onClick="javascript:history.go(-1)" class="unnamed5" style="font-size: 9pt; color: #000000; background-color: #EAEAF4; solid #EAEAF4" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#EAEAF4'">
<input type="submit" value=" 添 加 " name="Submit" class="unnamed5" OnClick="fnPreHandle()" style="font-size: 9pt; color: #000000; background-color: #EAEAF4; solid #EAEAF4" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#EAEAF4'">
<input type="reset" value=" 清 除 " name="Reset" class="unnamed5" style="font-size: 9pt; color: #000000; background-color: #EAEAF4; solid #EAEAF4" onMouseOver ="this.style.backgroundColor='#ffffff'" onMouseOut ="this.style.backgroundColor='#EAEAF4'">
</td>
</tr>
</form>
</table>
</td>
</tr>

</table>
</body>
</html>
NewsSave.asp 文件名

<!--#include file="Conn.asp"-->
<!--#include file="ChkManage.asp" -->
<%
title=request.form("title")
content=request.form("content")
set rs=server.createobject("adodb.recordset")
sql="select * from News"
rs.open sql,conn,1,3
rs.addnew
rs("title")=title
rs("content")=editor
rs("UpdateTime")=now()
rs.update
rs.close

Show_Message("<p align=center><font color=red>恭喜您,文章“"&title&"”已经成功添加!<br><br>"&freetime&"秒钟后返回上页!</font>")
response.end
%>

参考技术A 假如三天不见,谁会想念。当自己用答案去对照现实,你会流下几滴泪。每个人,最爱的是自己。即使你努力掩饰。 参考技术B

rs("content")=editor这句有问题吧

前面是content=request.form("content")

这里也要是rs("content")=content

KindEditor的使用和上传图片的后台处理

 应用环境:struts2,jsp。IE8下测试通过。

 

        kindeditor版本为3.5.4,官网下载后解压,取plugins、skins文件夹和kindeditor.js置于Web工程的WebRoot下。本文仅简单介绍如何使用kindeditor,并实现图片上传功能,页面上的提交功能未予实现。

 

       先来看页面

 

 
[java] view plaincopy
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
<%  
String path = request.getContextPath();  
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%>  
  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <base href="<%=basePath%>">  
      
    <title>kindeditor测试页面</title>  
      
    <meta http-equiv="pragma" content="no-cache">  
    <meta http-equiv="cache-control" content="no-cache">  
    <meta http-equiv="expires" content="0">      
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
    <meta http-equiv="description" content="This is my page">  
<script type="text/javascript" src="${pageContext.request.contextPath}/component/kindeditor/kindeditor.js"></script>  
    <script type="text/javascript">  
    KE.show({     
        id:‘content‘,   //下面的textarea的ID     
        height:‘500px‘,      
        resizeMode:0,        
        skinType:‘default‘,     
        autoOnsubmitMode:‘true‘,  
           
        //items选项可以去掉你不想要的功能,比如此处去掉上传flash的功能。没有这一项则默认开启所有功能  
        items : [  
            ‘source‘, ‘|‘, ‘fullscreen‘, ‘undo‘, ‘redo‘, ‘print‘, ‘cut‘, ‘copy‘, ‘paste‘,  
            ‘plainpaste‘, ‘wordpaste‘, ‘|‘, ‘justifyleft‘, ‘justifycenter‘, ‘justifyright‘,  
            ‘justifyfull‘, ‘insertorderedlist‘, ‘insertunorderedlist‘, ‘indent‘, ‘outdent‘, ‘subscript‘,  
            ‘superscript‘, ‘|‘, ‘selectall‘, ‘-‘,  
            ‘title‘, ‘fontname‘, ‘fontsize‘, ‘|‘, ‘textcolor‘, ‘bgcolor‘, ‘bold‘,  
            ‘italic‘, ‘underline‘, ‘strikethrough‘, ‘removeformat‘, ‘|‘, ‘image‘,  
            ‘advtable‘, ‘hr‘, ‘emoticons‘, ‘link‘, ‘unlink‘, ‘|‘, ‘about‘  
        ],  
        imageUploadJson:‘${pageContext.request.contextPath}/component/kindeditor/uploadImage.do‘  
    });   
    </script>   
  </head>  
    
  <body>  
    kindeditor测试页面 <br>  
    <form id="example" method="post" action="${pageContext.request.contextPath}/component/kindeditor/preview.do"> 
      <textarea id="content" name="content" style="width:700px;height:300px;visibility:hidden;"><br />  
      <input type="submit" value="提交内容"/> (提交快捷键: Ctrl + Enter)  
      </form>  
  </body>  
</html>  
 

       后台程序的处理

 

[java] view plaincopy
package org.wusq.ssx.component.kindeditor;  
  
import java.io.File;  
import java.io.FileNotFoundException;  
import java.io.IOException;  
import java.io.PrintWriter;  
import java.io.UnsupportedEncodingException;  
import java.util.Date;  
  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  
  
import org.apache.struts2.ServletActionContext;  
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;  
import org.springframework.stereotype.Controller;  
import org.wusq.ssx.util.ImageUtils;  
  
import com.opensymphony.xwork2.ActionSupport;  
  
/** 
 * KindEditor测试类 
 * @author wusq 
 * @since 2011-05-05 
 */  
@Controller  
public class KindEditor extends ActionSupport{  
      
    private static final long serialVersionUID = 6624518147834729694L;  
  
    //图片对象  
    private File imgFile;  
    //图片宽度  
    private String imgWidth;  
    //图片高度  
    private String imgHeight;  
    //图片对齐方式  
    private String align;  
    //图片标题  
    private String imgTitle;  
      
    public String uploadImage() throws Exception{  
        MultiPartRequestWrapper wrapper = (MultiPartRequestWrapper) ServletActionContext.getRequest();  
          
        //获得图片名字  
        String imgName = wrapper.getFileNames("imgFile")[0];  
          
        //获得图片后缀名  
        String fileExt = imgName.substring(imgName.lastIndexOf(".")).toLowerCase();  
          
        //重新生成图片名字  
        String imgN = new Date().getTime() + fileExt;  
          
        //图片在服务器上的绝对路径。编辑器并没有提供删除图片功能,此路径以后可以用于后台程序对图片的操作  
        String serverPath = "D://Program Files//Apache Software Foundation//Tomcat 6.0//webapps//ssx//uploadimage//";  
        //页面的引用地址  
        String savePath = "http://127.0.0.1:8080/ssx/uploadimage/";  
        //实际应用中鉴于地址的可变性,此处的两个path可以动态生成或从配置文件读取  
          
        kEUploadImage(ServletActionContext.getRequest(), ServletActionContext.getResponse(), imgFile, imgTitle, imgWidth, imgHeight, imgN, savePath, serverPath);  
          
        return null;  
    }  
      
    void kEUploadImage(HttpServletRequest request, HttpServletResponse response, File imgFile, String imgTitle, String imgWidth, String imgHeight, String imgName, String savePath, String serverPath)   
            throws FileNotFoundException, IOException{  
          
        //将图片写入服务器  
        ImageUtils.uploadToServer(imgFile, serverPath, imgName);  
          
        //页面回显  
        String id = "content";  
        String url = savePath + imgName;  
        String border = "0";        
        String result ="<mce:script type=/"text/javaScript/"><!--  
parent.KE.plugin[/"image/"].insert(/""       
        + id        
        + "/",/""       
        + url        
        + "/",/""       
        + imgTitle        
        + "/",/""       
        + imgWidth        
        + "/",/""      
         + imgHeight      
        + "/",/""      
        + border + "/""      
        +");  
// --></mce:script>";        
        PrintWriter out = null;   
        out = encodehead(request, response);  
        out.write(result);     
        out.close();  
    }  
      
    PrintWriter encodehead(HttpServletRequest request,HttpServletResponse response){  
        try {  
            request.setCharacterEncoding("utf-8");     
            response.setContentType("text/html; charset=utf-8");     
            return response.getWriter();  
        } catch (UnsupportedEncodingException e) {  
            e.printStackTrace();  
            return null;  
        } catch (IOException e) {  
            e.printStackTrace();  
            return null;  
        }     
    }  
      
    public File getImgFile() {  
        return imgFile;  
    }  
    public void setImgFile(File imgFile) {  
        this.imgFile = imgFile;  
    }  
    public String getImgWidth() {  
        return imgWidth;  
    }  
    public void setImgWidth(String imgWidth) {  
        this.imgWidth = imgWidth;  
    }  
    public String getImgHeight() {  
        return imgHeight;  
    }  
    public void setImgHeight(String imgHeight) {  
        this.imgHeight = imgHeight;  
    }  
    public String getAlign() {  
        return align;  
    }  
    public void setAlign(String align) {  
        this.align = align;  
    }  
    public String getImgTitle() {  
        return imgTitle;  
    }  
    public void setImgTitle(String imgTitle) {  
        this.imgTitle = imgTitle;  
    }  

 

        引用的工具类

 

[java] view plaincopy
package org.wusq.ssx.util;  
  
import java.io.File;  
import java.io.FileInputStream;  
import java.io.FileNotFoundException;  
import java.io.FileOutputStream;  
import java.io.IOException;  
  
/** 
 * 图片处理工具类 
 * @author wusq 
 * @since 2011-05-05 
 */  
public class ImageUtils {  
      
    /** 
     * 图片上传到服务器的方法 
     * @param upload 图片文件 
     * @param serverPath 保存在服务器的路径 
     * @param imgName 图片名字 
     * @since 2011-05-05 
     */  
    public static void uploadToServer(File upload, String serverPath, String imgName) throws FileNotFoundException, IOException{        
            File dirPath = new File(serverPath);  
            if(!dirPath.exists()){  
                dirPath.mkdirs();  
            }  
            String path = dirPath + "//" + imgName;  
            FileOutputStream fos = new FileOutputStream(path);        
            FileInputStream fis = new FileInputStream(upload);        
            byte[] buffer = new byte[1024];        
            int len = 0;        
            while ((len = fis.read(buffer)) > 0) {        
                fos.write(buffer, 0, len);        
            }        
            fos.close();        
            fis.close();  
    }  

 

转自:

以上是关于请教一下关于kindeditor与ASP后台整合,如何取到值提交数据库保存,帮忙改一下新手一个。全部分给你。的主要内容,如果未能解决你的问题,请参考以下文章

如何在Django后台添加HTML编辑器

请教高手,ASP建站时用IIS可以浏览前后台,知道前后台用户名和密码但是进不去,提示用户名不存在。

emblog个人博客管理系统后台升级编辑kindeditor到最新版本 详细步骤

kindeditor怎么获取获取HTML数据

kindeditor4整合SyntaxHighlighter,让代码亮起来

请教asp.net后台服务器实现定时功能怎么实现,说下思路也行