用百度编辑器发布新闻(UEditor的初始化开发部署)
来源:互联网 发布:iphone pro画笔软件 编辑:程序博客网 时间:2024/06/10 15:29
- 用百度编辑器发布新闻(UEditor的初始化开发部署)
- 编辑已发过的新闻(UEditor的应用——编辑旧文章)
- 上传附件、图片等
配置editor_config.js文件<%@ 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>百度编辑器开发实例</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> <script type="text/javascript" src="ueditor/editor_config.js"></script> <script type="text/javascript" src="ueditor/editor_all.js"></script> <LINKrel=stylesheet href="ueditor/themes/default/css/ueditor.css"> </head> <body> <form action="publish.action" method="post"> 类别: <input type="text" name="category" /><br/> 标题:<input type="text" name="title" /><br/> <textarea name="content" id="myEditor">这里写你的初始化内容</textarea><script type="text/javascript"> var editor = new UE.ui.Editor(); editor.render("myEditor"); //1.2.4以后可以使用一下代码实例化编辑器 //UE.getEditor('myEditor')</script><input type="submit" value="提交"/></form> </body></html>
将其改为:URL = window.UEDITOR_HOME_URL||tmp.substr(0,tmp.lastIndexOf("\/")+1).replace("_examples/","").replace("website/","");
URL = window.UEDITOR_HOME_URL||"/UEditorCase/ueditor/";
package xiaoxiao.action;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Map;import org.apache.struts2.ServletActionContext;import org.apache.taglibs.standard.lang.jstl.test.PageContextImpl;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;public class PublishAction extends ActionSupport {private String category;private String title;private String content;public String getCategory() {return category;}public void setCategory(String category) {this.category = category;}public String getTitle() {return title;}public void setTitle(String title) {this.title = title;}public String getContent() {return content;}public void setContent(String content) {this.content = content;}@Overridepublic String execute() throws Exception {//System.out.println("category:"+category);//System.out.println("title"+title);//System.out.println("content"+content);//String Date=new SimpleDateFormat("yyyy-MM-dd").format(new Date());//String realPath = ServletActionContext.getRequest().getRealPath("/upload")+"/"+Date;//System.out.println("路径"+realPath);ActionContext cxt=ActionContext.getContext();Map request=(Map)cxt.get("request");request.put("category", category);request.put("title", title);request.put("content", content);return SUCCESS;}}
show.jsp<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="strus" extends="struts-default" > <action name="publish" class="xiaoxiao.action.PublishAction"> <result name="success">/show.jsp</result> <!-- <result name="success">/editorUpdate.jsp</result> --> </action> </package></struts>
<%@ 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>信息发布</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css"> #showContent {WIDTH: 1000px;BACKGROUND: #e4eefa;FLOAT: left;border: 1px solid #FC9; } #showContent { MARGIN-BOTTOM: -32767px !important } </style> </head><body> 类别:${requestScope.category}<br> 标题:${requestScope.title}<br> 内容为:<br /><div id="showContent">${requestScope.content}</div></body></html>
将struts.xml中<%@ 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>My JSP 'editorUpdate.jsp' starting page</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"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> <script type="text/javascript" src="ueditor/editor_config.js"></script> <script type="text/javascript" src="ueditor/editor_all.js"></script> <LINKrel=stylesheet href="ueditor/themes/default/css/ueditor.css"> </head> <body> 编辑文章:<br/> <script type="text/plain" id="myEditor" name="content"> ${requestScope.content} </script><script type="text/javascript"> var editor = new UE.ui.Editor(); editor.render("myEditor"); //1.2.4以后可以使用一下代码实例化编辑器 //UE.getEditor('myEditor')</script> </body></html>
注释掉,改为:<result name="success">/show.jsp</result>
运行效果图:<result name="success">/editorUpdate.jsp</result>
由于采用了struts框架,拦截器把(/*)所有请求的文件都做了处理,所以导致无法上传图片和附件。<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="strus" extends="struts-default" > <action name="publish" class="xiaoxiao.action.PublishAction"> <result name="success">/show.jsp</result><!-- <result name="success">/editorUpdate.jsp</result> --></action> </package></struts>
步骤:
package xiaoxiao.filter;import java.io.IOException;import javax.servlet.FilterChain;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String url = request.getRequestURI(); String[] strs=url.split("/");//以/为分界拆分strs if(strs.length>3){ if("ueditor".equals(strs[2])&&"jsp".equals(strs[3])){ //System.out.println(strs[0]); 无 //System.out.println(strs[1]);UEditorCase //System.out.println(strs[2]);ueditor //System.out.println(strs[3]);jsp //System.out.println(strs[4]);//upload //System.out.println("自定义拦截"); chain.doFilter(req, res);//链式结构,当我定义的过滤器后不做操作就转到下一个过滤器,这里是我自己的过滤器,做了存图片的操作 }else{ //System.out.println("defaul"); super.doFilter(req, res, chain);//默认拦截器 } }else{ //System.out.println("defaul"); super.doFilter(req,res,chain); } }}
这样上传文件时,文件是保存在:/UeditorCase/ueditor/jsp/upload/ 文件夹下。<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><filter> <filter-name>struts2</filter-name> <filter-class>xiaoxiao.filter.MyStrutsFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
- 用百度编辑器发布新闻(UEditor的初始化开发部署)
- 百度编辑器ueditor的部署和二次开发
- 百度编辑器ueditor初始化赋值
- 百度编辑器ueditor初始化赋值
- javawebk开发百度编辑器ueditor的使用方法
- 百度UEditor的初始化
- Ueditor(百度编辑器)的使用
- ueditor(百度编辑器)的第一次使用
- UEditor(百度编辑器)的使用
- 发布百度ueditor编辑器 for django
- 百度编辑器ueditor的使用方法
- 百度编辑器ueditor的使用
- 百度编辑器Ueditor 初始化加载内容失败解决办法
- 百度编辑器ueditor的简单使用
- 百度编辑器ueditor的简单使用
- 百度编辑器Ueditor的黑白名单过滤
- 百度编辑器ueditor的简单使用
- 百度编辑器Ueditor的黑白名单过滤
- C++及Windows异常处理(try,catch; __try,__finally; __try, __except) ----一道笔试题引起的探究
- 怀疑博客被XSS(Cross Site Scripting)
- 用C++实现一个Log系统
- Android中BroadCastReceiver使用(整理)
- LeetCode 202:Happy Number
- 用百度编辑器发布新闻(UEditor的初始化开发部署)
- [脑洞] 将机器学习运用到计算机储存图像上?
- android-Making Applications Accessible
- 随笔
- 内存泄露从入门到精通三部曲之常见原因与用户实践
- JAVA并发编程笔记一
- 用JS写个简单的抢课脚本
- 谈控制吃烟
- 光流(optical flow) 光流法(optical flow method) 光流场(optical flow field)