FCKeditorのhtmlでの応用


1.Fckeditorのダウンロード
2.fckeditorフォルダをあなたのプロジェクトのWebRootルートの下にコピーします.
3.fckeditordemoというWebプロジェクトを新規作成
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.AddContentServiceletというサーブレットファイルを新規作成します.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();
	}

}