如何获取ckeditor中的内容
发布时间:2025-05-22 16:27:29 发布人:远客网络
一、如何获取ckeditor中的内容
第一步:找到需要放置CKEditor编辑器的页面,引入CKEditor的js文件(${contextPath}是JSTL写法,请改成你自己的路径写法,绝对路径或者相对路径):
<script type="text/javascript" src="${contextPath}/ckeditor4.1/ckeditor.js"></script>
第二步:在需要提交的form里,写一个:
<form id="detailForm" method="post">
<textarea id="content" name="content"></textarea>
<input type="button" value="保存" id="save" onclick="save()"/>
<script type="text/javascript">
editor= CKEDITOR.replace('content');//参数‘content’是textarea元素的name属性值,而非id属性值
第四步:在页面js中为CKEditor编辑器设置/获取值
editor.setData('这里是需要传递给CKEditor编辑器实例的值');
第五步:在后台java代码中获取CKEditor编辑器的值
<script type="text/javascript">
editor.updateElement();//非常重要的一句代码
二、js中如何获得焦点
利用js中<input/>实现文本框默认获取输入焦点完整代码实现如下:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
var pFocus= document.getElementById("password");
<body onload="autoFocus()">
<h1 style="font-size:1.5em;padding:20px;">输入密码</h1>
<form action="${pageContext.request.contextPath}/" method="post">
<input id="password" type="password" name="password">
<input type="submit" value="提交">
JavaScript使我们有能力创建动态页面。事件是可以被 JavaScript侦测到的行为。网页中的每个元素都可以产生某些可以触发JavaScript函数的事件。比方说,我们可以在用户点击某按钮时产生一个 onClick事件来触发某个函数。事件在HTML页面中定义。
三、关于servlet和jsp的问题
servlet是一种服务器的组件类,然而因为编程标准确实有servlet接口,但两者是不同的概念,不能混为一谈。
3.每一个jsp都可以在tomcat的work目录下寻找到相应的java文件(servlet),当浏览器发送一个请求比如:www.asdg.com/index.jsp,那么服务器先获取index.jsp文件,再通过一个相应的serlvet处理,然后再响应与jsp对应html字符串给浏览器进行渲染。我这边的index.jsp在tomcat的work目录下找到的相应项目的java文件如下
publicfinalclassindex_jspextendsorg.apache.jasper.runtime.HttpJspBase
implementsorg.apache.jasper.runtime.JspSourceDependent{
privatestaticfinalJspFactory_jspxFactory=JspFactory.getDefaultFactory();
privatestaticjava.util.List_jspx_dependants;
privatejavax.el.ExpressionFactory_el_expressionfactory;
privateorg.apache.AnnotationProcessor_jsp_annotationprocessor;
_el_expressionfactory=_jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_annotationprocessor=(org.apache.AnnotationProcessor)getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
publicvoid_jspService(HttpServletRequestrequest,HttpServletResponseresponse)
throwsjava.io.IOException,ServletException{
ServletContextapplication=null;
PageContext_jspx_page_context=null;
response.setContentType("text/html;charset=UTF-8");
pageContext=_jspxFactory.getPageContext(this,request,response,
_jspx_page_context=pageContext;
application=pageContext.getServletContext();
config=pageContext.getServletConfig();
session=pageContext.getSession();
Stringpath=request.getContextPath();
StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
out.write("<!DOCTYPEHTMLPUBLIC\"-//W3C//DTDHTML4.01Transitional//EN\">\r\n");
out.write("<html>\r\n");
out.write("<head>\r\n");
out.write("<title>MyJSP'index.jsp'startingpage</title>\r\n");
out.write("\t<metahttp-equiv=\"pragma\"content=\"no-cache\">\r\n");
out.write("\t<metahttp-equiv=\"cache-control\"content=\"no-cache\">\r\n");
out.write("\t<metahttp-equiv=\"expires\"content=\"0\">\r\n");
out.write("\t<metahttp-equiv=\"keywords\"content=\"keyword1,keyword2,keyword3\">\r\n");
out.write("\t<metahttp-equiv=\"description\"content=\"Thisismypage\">\r\n");
out.write("\t<linkrel=\"stylesheet\"type=\"text/css\"href=\"styles.css\">\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("<ahref=\"Hello.action\">Hello</a><br/><br/>\r\n");
out.write("<formaction=\"Login.action\">\r\n");
out.write("<inputtype=\"text\"name=\"username\"><br/>\r\n");
out.write("<inputtype=\"text\"name=\"password\"><br/>\r\n");
out.write("<inputtype=\"submit\"value=\"submit\">\r\n");
out.write("</form>\r\n");
out.write("</body>\r\n");
out.write("</html>\r\n");
if(!(tinstanceofSkipPageException)){
if(out!=null&&out.getBufferSize()!=0)
try{out.clearBuffer();}catch(java.io.IOExceptione){}
if(_jspx_page_context!=null)_jspx_page_context.handlePageException(t);
_jspxFactory.releasePageContext(_jspx_page_context);
}通过这种方式,就可以实现动态页面的效果。比如说,你在jsp页面中镶嵌了有java代码(用来显示数据),那么servlet类就会在组合html字符串的时候通过java代码来组合这些数据,从而实现动态效果。而如果使用html,它的响应机制是相同的,只是不需要再进行相应的servlet类的处理。如果使用html开发,基本流程和jsp差不多,web.xml配置,写servlet。只是你无法在html中动态嵌入数据,但是可以用js来处理,只是会比较麻烦