在提交之前记得 instance.post();

      这个应付老师检查还是可以的,但是很详细的怎么具体使用,还是要去看官方文档。

     

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>write</title> <link rel="stylesheet" href="../css/style_tinyeditor.css" /> <script type="text/javascript" src="../js/tinyeditor.js"></script> </head> <script type="text/javascript"> var instance ; window.onload = function() { instance = new TINY.editor.edit('editor', { id : 'input', width : 584, height : 175, cssclass : 'te', controlclass : 'tecontrol', rowclass : 'teheader', dividerclass : 'tedivider', controls : [ 'bold', 'italic', 'underline', 'strikethrough', '|', 'subscript', 'superscript', '|', 'orderedlist', 'unorderedlist', '|', 'outdent', 'indent', '|', 'leftalign', 'centeralign', 'rightalign', 'blockjustify', '|', 'unformat', '|', 'undo', 'redo', 'n', 'font', 'size', 'style', '|', 'image', 'hr', 'link', 'unlink', '|', 'cut', 'copy', 'paste', 'print' ], footer : true, fonts : [ 'Verdana', 'Arial', 'Georgia', 'Trebuchet MS' ], xhtml : true, cssfile : 'style.css', bodyid : 'editor', footerclass : 'tefooter', toggle : { text : 'source', activetext : 'wysiwyg', cssclass : 'toggle' }, resize : { cssclass : 'resize' } }); }; function refresh() { instance.post(); var title = document.getElementById("title").value; if (title == '') { alert("标题不能为空!") document.getElementById("title").focus(); return false ; } var input = document.getElementById("input").value; if (input == '') { alert("内容不能为空!"); document.getElementById("input").focus(); return false ; } return true ; } </script> <body> <form action="${pageContext.request.contextPath}/post_write.action" method="post" onsubmit="return refresh()"> 标题: <input type="text" name="title" style="width:400px;height: 20px; align:center;" id="title"> <textarea id="input" style="width:400px; height:200px" name="content"></textarea> <input type="submit" value="确定"> </form> </body> </html>

 显示的效果:

 

 

textarea中的数据保存在数据库中的格式为:我用的数据库为mysql字段是用的longtext;

 最后显示在数据库中的内容为:

 

将数据库中的数据用ognl表达式显示到页面上 ,刚开始我试过用js调用innerHTML将内容和html代码注入进去,但是会出现转义的问题,不知道是不是我写的有问题,但是下面这种写法是可以的。

<s:property value="post.content" escape="false" />//重要的是escape="false"这个属性,不然会将标签同时显示出来


 

 

 

posted on 2016-05-30 12:46  麦田里的稻草人19994  阅读(166)  评论(1编辑  收藏  举报