最近在学习KindEditor插件,一款蛮不错的编辑器插件。在此将心得写出来,希望对大家有所帮助。
最终实现的效果如图所示:
(1)在管理员页面manage.jsp点击”添加新闻“按钮。
(2)可以从网络上面复制粘贴一篇文章,也可以自己编写文章。现在测试图片从其他网站复制粘贴的情况。
(3)点击提交,提示提交成功后,进入主页面index.jsp,发现刚才编辑的文章已经显示出来。
(4)这时候点击标题,可以正常显示文章来。
(5)除此外还可以实习本地图片的上传,文档的上传下载等功能。还有对上传的文章进行修改等功能。
实现步骤:
1、在Eclipse或者Myeclipse中搭建KindEditor环境,可以查照我先前的博客的做法:
http://blog.csdn.net/lhq13400526230/article/details/9256301
2、在Oracle中设计一张表名为news的数据库表。之所以有主键和业务主键,是为了让业务和主键无关系
3、创建工程,工作的目录如图所示:包括控制层(Action)、模型层(model)、接口(Service)、接口的实现类(ServiceImpl)、Spring配置(applicationContext.xml)、Spring的数据库配置(applicationContext_db.xml)、Spring的依赖注入(applicationContext_bean.xml)、存放上传图片、文件的目录的文件夹attached、存放KindEditor插件的文件夹KindEditor-4.1.7、存放JSP页面的文件夹JSP、存放新闻主页的JSP--index.jsp、存放管理员首页的JSP---manage.jsp等等。
4、web.xml配置
<?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"> <!-- Sttuts2过滤器 --> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <!-- 监听器Spring --> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 定位applicationContext.xml的物理位置 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> </web-app>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <import resource="applicationContext_bean.xml"/> <import resource="applicationContext_db.xml"/> </beans>
package news.model; import java.sql.Blob; import java.util.Date; public class News { private String id;//主键 private String newsid;//新闻主键 private String title;//新闻标题 private byte[] content;//新闻内容 private Date times;//新闻发布时间 private String types;//新闻类型 private String author;//新闻作者 private String department;//新闻发布部门 public String getId() { return id; } public void setId(String id) { this.id = id; } public byte[] getContent() { return content; } public void setContent(byte[] content) { this.content = content; } public String getNewsid() { return newsid; } public void setNewsid(String newsid) { this.newsid = newsid; } public Date getTimes() { return times; } public void setTimes(Date times) { this.times = times; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getTypes() { return types; } public void setTypes(String types) { this.types = types; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } }
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated 2013-7-5 15:57:38 by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="news.model.News" table="NEWS"> <id name="id" type="java.lang.String"> <column name="ID" /> <generator class="assigned" /> </id> <property name="newsid" type="java.lang.String"> <column name="NEWSID" /> </property> <property name="title" type="java.lang.String"> <column name="TITLE" /> </property> <property name="content" > <column name="content" /> </property> <property name="times" type="java.util.Date"> <column name="TIMES" /> </property> <property name="types" type="java.lang.String"> <column name="TYPES" /> </property> <property name="author" type="java.lang.String"> <column name="AUTHOR" /> </property> <property name="department" type="java.lang.String"> <column name="DEPARTMENT" /> </property> </class> </hibernate-mapping>
package news.service; import java.util.List; import news.model.News; public interface NewsService { public String saveNews(News news,String content) throws Exception;//保存编译的新闻 public List findNews(String newsid) throws Exception;//显示新闻内容 public List listNews(String type) throws Exception;//显示新闻列表 public void updateShowNews(News n) throws Exception;//更新新闻 }
package news.serviceImpl; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; import news.action.NewsAction; import news.model.News; import news.service.NewsService; import org.apache.log4j.Logger; import org.hibernate.Query; import org.hibernate.SessionFactory; public class NewsServiceImpl implements NewsService{ static Logger log = Logger.getLogger(NewsServiceImpl.class); private SessionFactory sessionFactory; //保存数据 public String saveNews(News news,String htmlData) throws Exception { String uuid=UUID.randomUUID().toString();//UUID产生主键 byte content[]=htmlData.getBytes("utf-8");//String类型转化为Byte类型 log.info("信息:"+htmlData); Date date=new Date();//产生时间 DateFormat datefor = new SimpleDateFormat("yyyy-MM-dd-HHmmssFFFF");//时间格式化 String neswid = datefor.format(date); news.setId(uuid);//设置主键 news.setNewsid(neswid);//设置新闻主键 news.setTimes(date);//设置时间 news.setContent(content);//设置内容 this.sessionFactory.getCurrentSession().save(news); return neswid; } //修改新闻 public void updateShowNews(News n) throws Exception { this.sessionFactory.getCurrentSession().update(n); } //显示新闻的标题栏 public List listNews(String type) throws Exception { String sql = " from News t where t.types=:types "; Query query=this.sessionFactory.getCurrentSession().createQuery(sql); query.setParameter("types", type);//新闻编号 return query.list(); } //根据新闻业务主键newsid查询新闻 public List findNews(String newsid) throws Exception { String sql = " from News t where t.newsid=:newsid "; Query query=this.sessionFactory.getCurrentSession().createQuery(sql); query.setParameter("newsid", newsid);//新闻编号 return query.list(); } public SessionFactory getSessionFactory() { return sessionFactory; } public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory = sessionFactory; } }
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 用Bean定义数据源 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <!-- 定义数据库驱动 --> <property name="driverClass"> <value>oracle.jdbc.driver.OracleDriver</value> </property> <!-- 定义数据库URL --> <property name="jdbcUrl"> <value>jdbc:oracle:thin:@localhost:1521:orcl</value> </property> <!-- 定义数据库的用户名 --> <property name="user"> <value>lhq</value> </property> <!-- 定义数据库的密码 --> <property name="password"> <value>lhq</value> </property> <property name="minPoolSize"> <value>1</value> </property> <property name="maxPoolSize"> <value>40</value> </property> <property name="maxIdleTime"> <value>1800</value> </property> <property name="acquireIncrement"> <value>2</value> </property> <property name="maxStatements"> <value>0</value> </property> <property name="initialPoolSize"> <value>2</value> </property> <property name="idleConnectionTestPeriod"> <value>1800</value> </property> <property name="acquireRetryAttempts"> <value>30</value> </property> <property name="breakAfterAcquireFailure"> <value>true</value> </property> <property name="testConnectionOnCheckout"> <value>false</value> </property> </bean> <!--定义Hibernate的SessionFactory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!-- 定义SessionFactory必须注入dataSource --> <property name="dataSource"> <ref bean="dataSource" /> </property> <!-- 定义Hibernate的SessionFactory属性 --> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect"> org.hibernate.dialect.Oracle10gDialect </prop> </props> </property> <!-- 定义POJO的映射文件 --> <property name="mappingResources"> <list> <value>news/model/News.hbm.xml</value> </list> </property> </bean> <!-- 配置事务拦截器 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED" /><!-- 只有一save、delete、update开头的方法才能执行增删改操作 --> <tx:method name="delete*" propagation="REQUIRED" /> <tx:method name="update*" propagation="REQUIRED" /> <tx:method name="*" propagation="SUPPORTS" read-only="true" /><!-- 其他方法为只读方法 --> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="interceptorPointCuts" expression="execution(* news.serviceImpl..*.*(..))" /> <!-- 对应实现类接口的包的位置 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="interceptorPointCuts" /> </aop:config> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"> <!-- 业务层Service --> <bean id="news_service" class="news.serviceImpl.NewsServiceImpl"> <property name="sessionFactory"> <ref bean="sessionFactory"></ref> </property> </bean> <!-- 控制层Action --> <bean id="news_action" class="news.action.NewsAction"> <property name="news_services"> <ref bean="news_service" /> </property> </bean> </beans>
package news.action; import java.io.UnsupportedEncodingException; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import news.model.News; import news.service.NewsService; import org.apache.log4j.Logger; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionContext; public class NewsAction { static Logger log = Logger.getLogger(NewsAction.class); private NewsService news_services; private News news; //保存编辑的新闻信息 public String saveNews() throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); String htmlData = request.getParameter("content1");//获取页面的数据 news_services.saveNews(news,htmlData); return "saveNewsSuccess"; } //获取要更新新闻的信息 public String updateContent() throws Exception { HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); String htmlData=request.getParameter("content1"); log.info("新闻的主键============="+news.getId()); log.info("新闻的内容============="+htmlData); byte content[]=htmlData.getBytes("utf-8"); news.setContent(content); news_services.updateShowNews(news); return "updateContentSuccess"; } //查找新闻的详细信息 public String showNews() throws Exception{ HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); String newsid=news.getNewsid();//从页面获取要查看的新闻ID List list=news_services.findNews(newsid); News n=(News) list.get(0); DateFormat datefor = new SimpleDateFormat("yyyy-MM-dd HH:mm");//时间格式化 String times = datefor.format(n.getTimes()); String CONTENT=new String(n.getContent());//将byte数组转化为String类型 String auhtor=n.getAuthor(); String title=n.getTitle(); String types=n.getTypes(); String department=n.getDepartment(); String id=n.getId(); String no=n.getNewsid(); request.setAttribute("id", id); request.setAttribute("newsid", no); request.setAttribute("department", department); request.setAttribute("title", title); request.setAttribute("types", types); request.setAttribute("content", CONTENT); request.setAttribute("times", times); request.setAttribute("author", auhtor); return "showNewsSuccess"; } //分别罗列出各个新闻的列表 public String NewsList() throws Exception{ Map request = (Map) ActionContext.getContext().get("request");//属于 List list=news_services.listNews("国际新闻"); request.put("list_guoji", list); List list2=news_services.listNews("国内新闻"); request.put("list_guonei", list2); List list3=news_services.listNews("体育新闻"); request.put("list_tiyu", list3); List list4=news_services.listNews("娱乐新闻"); request.put("list_yule", list4); return "sucess"; } public NewsService getNews_services() { return news_services; } public void setNews_services(NewsService news_services) { this.news_services = news_services; } public News getNews() { return news; } public void setNews(News news) { this.news = news; } }
<?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> <constant name="struts.multipart.saveDir" value="/tmp"></constant> <package name="default" extends="struts-default"> <action name="saveNewsAction" class="news_action" method="saveNews"> <result name="saveNewsSuccess">/jsp/success.jsp</result><!--保存编辑信息信息成功跳转页面 --> </action> <action name="showNewsAction" class="news_action" method="showNews"> <result name="showNewsSuccess">/jsp/show_news_content.jsp</result><!--读取新闻信息 --> </action> <action name="showNewsListAction" class="news_action" method="NewsList"> <result name="sucess">/jsp/show_news_list.jsp</result><!--读取新闻列表信息 --> </action> <action name="manageNewsListAction" class="news_action" method="NewsList"> <result name="sucess">/jsp/manage_news_list.jsp</result><!--读取新闻列表信息 --> </action> <action name="updateNewsAction" class="news_action" method="showNews"> <result name="showNewsSuccess">/jsp/manage_news_content.jsp</result><!--读取新闻列表信息 --> </action> <action name="updateContentAction" class="news_action" method="updateContent"> <result name="updateContentSuccess">/jsp/updateSuccess.jsp</result><!--修改新闻列表信息 --> </action> </package> </struts>
15、index.jsp用于新闻网站的首页
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>新闻主页</title> </head> <body > <div align="center"> <table> <tr> <td><h2 align="center">新闻频道</h2></td> </tr> <tr> <td> <iframe id="mainframe" src="showNewsListAction.action" name="mainframe" frameborder="0" scrolling="no" width="800px" height="100%"> </iframe></td> </tr> </table> </div> </body> <script type="text/javascript"> function reinitIframe(){ var iframe = document.getElementById("mainframe"); try{ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; }catch (ex){} } window.setInterval("reinitIframe()", 200); </script> </html>
16、show_news_list.jsp用于显示查询到已经发表的新闻列表。显示的只是新闻的标题,不是内容。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% request.setCharacterEncoding("UTF-8"); String htmlData = request.getParameter("content1") != null ? request .getParameter("content1") : ""; %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>新闻显示列表页面</title> </head> <body> <div style="float:right;width:350px;height:200px;"> <table> <tr> <td> <h3>国际新闻</h3> </td> </tr> <s:iterator value="#request.list_guoji" id="news1"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news1.newsid"/>"> <s:property value="#news1.title" /> </a></td> </tr> </s:iterator> </table> </div> <div style="float:left;width:350px;height:200px;"> <table> <tr> <td> <h3>国内新闻</h3> </td> </tr> <s:iterator value="#request.list_guonei" id="news2"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news2.newsid"/>"> <s:property value="#news2.title" /> </a></td> </tr> </s:iterator> </table> </div> <div style="float:right;width:350px;height:200px;"> <table> <tr> <td> <h3>体育新闻</h3> </td> </tr> <s:iterator value="#request.list_tiyu" id="news3"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news3.newsid"/>"> <s:property value="#news3.title" /> </a></td> </tr> </s:iterator> </table> </div> <div style="float:left;width:350px;height:200px;"> <table> <tr> <td> <h3>娱乐新闻</h3> </td> </tr> <s:iterator value="#request.list_yule" id="news4"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news4.newsid"/>"> <s:property value="#news4.title" /> </a></td> </tr> </s:iterator> </table> </div> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>新闻内容</title> </head> <body> <div align="center"> <div> <table> <tr> <td></td> </tr> <tr> <td>发布时间:<%=request.getAttribute("times")%></td> <td>作者:<%=request.getAttribute("author")%></td> </tr> </table> </div> <hr> <div> <%=request.getAttribute("content")%> </div> </div> </body> </html>
18、manage.jsp管理员的主页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% String path = request.getContextPath(); request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>管理员页面</title> </head> <body > <div align="center"> <h2 align="center">管理员操作</h2> <table> <tr> <td><a href="<%=path %>/jsp/add.jsp">添加新闻</a></td> </tr> <br> <tr> <td><a href="<%=path %>/update.jsp">修改新闻</a></td> </tr> </table> </div> </body> </html>
19、add.jsp管理员用来添加新闻的页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); request.setCharacterEncoding("UTF-8"); String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : ""; %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>KindEditor JSP</title> <link rel="stylesheet" href="<%=path%>/kindeditor-4.1.7/themes/default/default.css" /> <link rel="stylesheet" href="<%=path%>/kindeditor-4.1.7/plugins/code/prettify.css" /> <script charset="utf-8" src="<%=path%>/kindeditor-4.1.7/kindeditor.js"></script> <script charset="utf-8" src="<%=path%>/kindeditor-4.1.7/lang/zh_CN.js"></script> <script charset="utf-8" src="<%=path%>/kindeditor-4.1.7/plugins/code/prettify.js"></script> <script> KindEditor.ready(function(K) { var editor1 = K.create('textarea[name="content1"]', { cssPath : 'kindeditor-4.1.7/plugins/code/prettify.css', uploadJson : 'kindeditor-4.1.7/jsp/upload_json.jsp', fileManagerJson : 'kindeditor-4.1.7/jsp/file_manager_json.jsp', allowFileManager : true, afterCreate : function() { var self = this; K.ctrl(document, 13, function() { self.sync(); document.forms['example'].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); document.forms['example'].submit(); }); } }); prettyPrint(); }); </script> </head> <body> <div align="center"> <form name="example" method="post" action="saveNewsAction.action"> <h4>文章编辑</h4> <table> <tr> <td>标题</td> <td><input type="text" name="news.title" /></td> <td>作者</td> <td><input type="text" name="news.author" /></td> <td>类型</td> <td> <select name="news.types"> <option>国内新闻</option> <option>国际新闻</option> <option>体育新闻</option> <option>娱乐新闻</option> </select> </td> <td>发布单位</td> <td> <select name="news.department"> <option>办公室</option> <option>宣传部</option> <option>文艺团</option> <option>工会</option> </select> </td> </tr> </table> <textarea name="content1" cols="100" rows="8" style="width:800px;height:450px;visibility:hidden;margin:0px 100px 0px 100px;"><%=htmlspecialchars(htmlData)%></textarea> <br /> <input type="submit" name="button" value="提交内容" /> (提交快捷键: Ctrl + Enter) </form> </div> </body> </html> <%! private String htmlspecialchars(String str) { str = str.replaceAll("&", "&"); str = str.replaceAll("<", "<"); str = str.replaceAll(">", ">"); str = str.replaceAll("\"", """); return str; } %>
20、提示新闻添加成功的页面success.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>成功页面</title> </head> <body> 发布成功!! </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>管理员页面</title> </head> <body > <div align="center"> <table> <tr> <td><h2 align="center">管理员操作</h2></td> </tr> <tr> <td> <iframe id="mainframe" src="manageNewsListAction.action" name="mainframe" frameborder="0" scrolling="no" width="800px" height="100%"> </iframe></td> </tr> </table> </div> </body> <script type="text/javascript"> function reinitIframe(){ var iframe = document.getElementById("mainframe"); try{ var bHeight = iframe.contentWindow.document.body.scrollHeight; var dHeight = iframe.contentWindow.document.documentElement.scrollHeight; var height = Math.max(bHeight, dHeight); iframe.height = height; }catch (ex){} } window.setInterval("reinitIframe()", 200); </script> </html>
22、manage_news_list.jsp显示可以更新的新闻列表
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% request.setCharacterEncoding("UTF-8"); String htmlData = request.getParameter("content1") != null ? request .getParameter("content1") : ""; %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>新闻管理页面</title> </head> <body> <div style="float:right;width:350px;height:200px;"> <table> <tr> <td> <h3>国际新闻</h3> </td> </tr> <s:iterator value="#request.list_guoji" id="news1"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news1.newsid"/>"> <s:property value="#news1.title" /> </a></td> <td><a href="updateNewsAction.action?news.newsid=<s:property value="#news1.newsid"/>"> 修改新闻 </a></td> </tr> </s:iterator> </table> </div> <div style="float:left;width:350px;height:200px;"> <table> <tr> <td> <h3>国内新闻</h3> </td> </tr> <s:iterator value="#request.list_guonei" id="news2"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news2.newsid"/>"> <s:property value="#news2.title" /> </a></td> <td><a href="updateNewsAction.action?news.newsid=<s:property value="#news2.newsid"/>"> 修改新闻 </a></td> </tr> </s:iterator> </table> </div> <div style="float:right;width:350px;height:200px;"> <table> <tr> <td> <h3>体育新闻</h3> </td> </tr> <s:iterator value="#request.list_tiyu" id="news3"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news3.newsid"/>"> <s:property value="#news3.title" /> </a></td> <td><a href="updateNewsAction.action?news.newsid=<s:property value="#news3.newsid"/>"> 修改新闻 </a></td> </tr> </s:iterator> </table> </div> <div style="float:left;width:350px;height:200px;"> <table> <tr> <td> <h3>娱乐新闻</h3> </td> </tr> <s:iterator value="#request.list_yule" id="news4"> <tr> <td><a href="showNewsAction.action?news.newsid=<s:property value="#news4.newsid"/>"> <s:property value="#news4.title" /> </a></td> <td><a href="updateNewsAction.action?news.newsid=<s:property value="#news4.newsid"/>"> 修改新闻 </a></td> </tr> </s:iterator> </table> </div> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); request.setCharacterEncoding("UTF-8"); String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : ""; %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>KindEditor JSP</title> <link rel="stylesheet" href="<%=path%>/kindeditor-4.1.7/themes/default/default.css" /> <link rel="stylesheet" href="<%=path%>/kindeditor-4.1.7/plugins/code/prettify.css" /> <script charset="utf-8" src="<%=path%>/kindeditor-4.1.7/kindeditor.js"></script> <script charset="utf-8" src="<%=path%>/kindeditor-4.1.7/lang/zh_CN.js"></script> <script charset="utf-8" src="<%=path%>/kindeditor-4.1.7/plugins/code/prettify.js"></script> <script> KindEditor.ready(function(K) { var editor1 = K.create('textarea[name="content1"]', { cssPath : 'kindeditor-4.1.7/plugins/code/prettify.css', uploadJson : 'kindeditor-4.1.7/jsp/upload_json.jsp', fileManagerJson : 'kindeditor-4.1.7/jsp/file_manager_json.jsp', allowFileManager : true, afterCreate : function() { var self = this; K.ctrl(document, 13, function() { self.sync(); document.forms['example'].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); document.forms['example'].submit(); }); } }); prettyPrint(); }); </script> </head> <body> <div align="center"> <form name="example" method="post" action="updateContentAction.action"> <h4>文章修改</h4> <table> <tr style="display: none;"> <td><input type="text" name="news.id" value="<%=request.getAttribute("id")%>" /></td> <td><input type="text" name="news.newsid" value="<%=request.getAttribute("newsid")%>" /></td> <td><input type="text" name="news.times" value="<%=request.getAttribute("times")%>" /></td> </tr> <tr> <td>标题</td> <td><input type="text" name="news.title" value="<%=request.getAttribute("title")%>" /></td> <td>作者</td> <td><input type="text" name="news.author" value="<%=request.getAttribute("author")%>" /></td> <td>类型</td> <td> <select name="news.types"> <option ><%=request.getAttribute("types")%></option> <option >国内新闻</option> <option >国际新闻</option> <option >体育新闻</option> <option >娱乐新闻</option> </select> </td> <td>发布单位</td> <td> <select name="news.department" > <option><%=request.getAttribute("department")%></option> <option>办公室</option> <option>宣传部</option> <option>文艺团</option> <option>工会</option> </select> </td> </tr> </table> <textarea name="content1" cols="100" rows="8" style="width:800px;height:450px;visibility:hidden;margin:0px 100px 0px 100px;"><%=request.getAttribute("content")%></textarea> <br /> <input type="submit" name="button" value="提交内容" /> (提交快捷键: Ctrl + Enter) </form> </div> </body> </html>
21、updateSuccess.jsp提示新闻修改成功的页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% request.setCharacterEncoding("UTF-8"); %> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>成功页面</title> </head> <body> 修改成功!! </body> </html>
管理员的网址:http://localhost:8080/news/manage.jsp
普通用户的网址:http://localhost:8080/news/index.jsp