FCKeditor在html中的应用

1.下载Fckeditor

2.把fckeditor文件夹拷贝到你项目的中WebRoot 根目录下;

3.新建一个web project 项目 起名为fckeditordemo

4.在fckeditordemo 项目中 新建一个名为input.html文件. 代码如下

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>input.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
   <script src="fckeditor/fckeditor.js"></script>
   请输入内容<br>
   <form name="form3" id="form3" method="post" action="/fckeditordemo/servlet/addContent">
   <input name="title" type="text"><br>
   <script>
   var editor=new FCKeditor('editor1');
   editor.BasePath='/fckeditordemo/fckeditor/';
   editor.Height='200';
   editor.ToolBarSet='Default';
   editor.Create();
   </script>
   <input type="submit" name="submit" value="submit">
   </form>
  </body>
</html>

 

5.新建一个Servlet文件 名为AddContentServlet.java

映射改为addContent

代码如下:

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class AddContentServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8"); 
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("utf-8");
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.println("主题:<br>");
		out.println(request.getParameter("title")+"<br>");
		out.println("内容:<br>");
		out.println(request.getParameter("editor1"));
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}

}

 

你可能感兴趣的:(html,Web,servlet,css,fckeditor)