javaserverprogramming markdown memo


  • コメントアウト: \ (エスケープシーケンス)
  • 見出し(強調): # 増えるほど強調できる
  • 太字:"*"で囲む(または"__")
  • イタリック:"**"で囲む(または"__")
  • リンク:表示名
  • シンタックスハイライト:言語で囲む
  • 改行:
  • 順序付きリスト: (空行) 1.(空白)リスト1 1.(空白)リスト2 (空行)

  • 順序無し(・)リスト: (空行) +(or-or)(空白)リストA +(or-or)(空白)リストB (空行)

  • 一部だけコードハイライト gccの例:gcc hello.c


  • e: go to last character of word on cursor
  • b: back to a left word
  • o: go to insert mode at new line
  • gg: go to begining of file
  • G:go to end of file
  • 3G: go to line "3"
  • dw: delete word to right side
  • yy: copy one line
  • p: paste buffer
  • ctrl+r: redo
  • /(スラッシュ)検索したい言葉:検索(まずはenter押す、nで次へ移動)
  • :s/old/new : 置換(oldをnewに)
  • :s/old/new/g : その一行で全部置換
  • :%s/old/new/gc:そのファイル全部で置換(c:一回ずつ確認を求める)


link: リンク表示名 ex: リンク表示名 :home directory

java server side programming perfect master memo

chapter 3

3-1 create new project

*java web->webアプリケーション
*GlassFish Server
*java EE 7 web

3-2 what occurs when "run"

run means compile and deploy (create .war file and copy this war file to GlassFish server)

3-3 create a servlet file

Do right click on project name and 新規 -> servlet input form, class name: arbitrary class name package: com.example next input form, servlet name; arbitrary servlet name url pattern kind: /arbitrary url pattern(recommend: servlet name)

3-4 what is servlet?

servlet is a java class

?how to use servlet

servlet instance can dynamically create contents (ex.html code)

JSP&servlet container in application server
it has main() method and other useful method
JSP&servlet container create instance of servlet class
through main() method 
servlet instance create contents (ex.html code)

3-5 default servlet

method of default servlet * processReauest(HttpServletRequest, HttpServletResponse) this method create a http page depending on client's request grammer point : out.println("<!DOCTYPE html>"); out.println(""); ... so, this method create html code from below code out.println("html sources")

* doGet(HttpServletRequest, HttpServletResponse)
    it work as HTTP GET method
* doPost(HttpServletRequest, HttpServletResponse)
    it work as HTTP POST method

4-1 modern client/server model is 3 layer system

3 layer system 
    * client , server , middle tier(中間層)
    * middle tier(java EE) 
        * presentation layer: appearence of web page
        * business logic layer: process data
        * datalink layer: save and read data

5-1 MVC on javaEE

  • view : xhtml + backing bean(managed bean) xhtml is similar to html but tag is not same backing beans preserve values from input on view

  • model: connect database

  • controller: jsf(facesServlet)

  • important: Not only controller(FacesServlet) has action method backing beans also has action method(mainly called by jsf to deal with client's input.)

5-2 set jsf(controller) and API and encoding files

reproduced below as 3-1

* java web -> webアプリケーション
* GlassFish Server
* java EE 7 web
* コンテキストpathはそのまま
* frame work -> check on JavaServer Faces
(finish button)
* add API librar
    project window -> (right click)ライブラリ -> ライブラリの追加
    -> check on Java EE 7 APIライブラリ
* set character encoding
    project window -> (right click)project name -> 新規 -> その他
    (category)GlassFish -> GlassFishディスクリプタ
    then, create 構成ファイル/glassfish-web.xml
    add below code at line 2 from bottom of glassfish-web.xml
      <parameter-encoding default-charset="UTF-8"/>  

5-3 make table(list)

use jsf in other words, a xhtml file

  • <h:form> tag : need to input and send message
  • xhtml tags for making table(list) (in <h:form> tag) <h:panelGrid> tag example: <h:panelGrid columns ="number of columns" > </h:panelGrid>

  • set label (in <h:form> tag) <h:outputLabel> tag example: <h:outputLabel value="ISBN : "/>

  • set textfield (in <h:form> tag) <h:inputText> tag example: <h:inputText value="#{book.isbn}"/>

  • set button to send input (in <h:form> tag) <h:commandButton> tag example: <h:commandButton value="送信" actionListener="#{book.dispConsole()}" />

  • draw a line to devide between sections

    tag it is used only "
    " in other words, Dont use

5-4 backing beans, midiator between view and model(database)

  • backing beans is java file role: midiator between view and model(database) preserve values of client's inputs have action (class)method, it will work if jsf call. view and database use this preserved values(class field)

  • automatically make getter/setter method 1.at the first time, you add (private) field, 2.go to editor of backing beans file,if right click and select "insert code" 3.select "取得メソッド及び設定メソッド" 4.select field you want to deal with by getter/setter

  • intantiation of backing beans and CDI CDI(Contexts Dependency Injection) CDI manages instance's relation of dependency and lifecycle of objects

    by anotation, CDI create a instance example: (in backing beans file) //import files for annotation of instantiation import javax.enterprise.context.RequestScoped; import javax.inject.Named; //specify(指定する) a rule of instance's name @Named //it manages to autorelease objects @RequestScoped public class Book { private String isbn; }

5-5 setting of environment of FacesServlet(controller)