JAVA Web 02——JSPのページ要素、JSP九大内蔵オブジェクト


目次
 
一、JSPのページ要素
1.JAVAコード(スクリプトScriptlet)
2.指令
3.コメント
二、JSP九大内蔵対象
1.out:オブジェクトを出力し、クライアントにコンテンツを出力する
2.request:要求対象、「クライアントがサービス側に送信した要求情報
3.response:応答オブジェクト
4.session
クッキーとセッションの違い
クッキー(クライアント、内蔵オブジェクトではなくnewを使用する必要があります)
セッション:セッション
sessionメカニズム
5.アプリケーション:グローバルオブジェクト
6.pageContext:JSPページコンテナ
7.config:構成オブジェクト(サーバ構成情報)
8.page:現在のJSPページオブジェクト(JAVAのthisに相当)
9.exception:例外オブジェクト
4つの範囲オブジェクト(小さいものから大きいものまで)
①pageContext JSPページコンテナ
②リクエスト対象
③セッションオブジェクト
④アプリケーショングローバルオブジェクト
一、JSPのページ要素
1.JAVAコード(スクリプトScriptlet)

ローカル変数、Java文%>

グローバル変数、定義方法%>

 
eg:





Insert title here


	
	
	
	


Webを変更します.xml、プロファイル、javaは、Tomcatサービスを再起動してJsptmlcssjsを変更する必要があります.再起動する必要がないprint出力はHTMLテキストです.
2.指令
Page命令:

page :

  • language:jsp
  • import:
  • pageEncoding:jsp jsp->java
  • contentType: jsp
    import="java.util.Date"

3.

、JSP

, new

1.out: ,

2.request: , “

  • String getParameter(String name): key, value
  • String[] getParameter(String name): key, value(checkbox)
  • void setCharacterEncoding(" utf-8"): (tomcat7 iso-8859-1,tomcat8 utf-8)
  • getRequestDisatcher("b.jsp").forward(request, response): A->B
  • ServletContent getSeverContent(): ServletContent


register.jsp






Insert title here


	

show.jsp






Insert title here


	
	
	    ,    :
	  :
	  :
	  :
	  :
	

 get :method="get" 、 () のデフォルトはすべてget getとpost の いに する:get はアドレスバーに を する(しかしアドレスバーが できる は られており、4-5 KB);postはファイルアップロード を せず、POSTがPOSTを して する がある

3.response:


void addCookie(Cookie cookie): cookie
void sendRedirect(String location) throws IOException: ( )
void setContentType(String type): ( contentType )

login.jsp -> check.jsp -> success.jsp

login.jsp
 






Insert title here


	

 check.jsp
 






Insert title here


	

 success.jsp
 






Insert title here


	    !
	   :
	
	

 
1 2

4.session

cookie session

  session cookie
Object String

cookie( , , new)

Cookie , 。
: ->
      : ,
      Cookie:name=value
      javax.servlet.http.Cookie
① cookie:
      public Cookie(String name,String value)
      String getName()
      String getValue()
      void setMaxAge(int expiry); ( )
② Cookie:
response.addCookie(Cookie cookie)
③ ( , )
④ cookie:
request.getCookies();
~ cookie:response ; :resquest
~ , cookie
F12 Cookie , name JSESSIONID cookie
cookie , 、
, JESSION cookie: , JSESSIONID, name=JSESSIONID Cookie
eg: Cookie
login.jsp






Insert title here



	
	

	
"> :

 check.jsp






Insert title here


	

session:

: -
: 、 、
: 、 、

session

,(jsessionid - sessionid , ) session ( )
session sessionId( session)
cookie, cookie name=JSESSIONID,value= sessionId
cookie , cookie(JSESSIONID)
, cookie session (JSESSION - sessionID)

/n : cookie JSESSIONID session sessionid, (cookie jsessionid session sessionid) , ;

session:
1、session
2、session ( )
3、 : sessionid cookie jsession 。 session sessionid-cookie jsessionid

session :
String getId(): sessionId
boolean isNew(): ( )
void invalidate(): session ( 、 )

void setAttribute()
Object getAttribute()

void setMaxInactiveInterval( ):
int getMaxInactiveInterval():

: 、
request:
login.jsp






Insert title here


	

check.jsp






Insert title here


	

welcome.jsp
 






Insert title here


	    !
	   :
	
		ログアウト
	

5.application:

String getContextPath()
String getRealPath(String name) ( )

"%>
"%>

 

6.pageContext:JSP

7.config: ( )

8.page: JSP ( JAVA this)

9.exception:

( )

pageContext JSP  
request                 
session                 
appliation                ( )


Object getAttribute(String name): ,
void setAttribute(String name,Object obj): ( , )
void removeAttribute(String name): ,

①pageContext JSP   

,

②request 

, ( , )

③session 

( , ; / ; )

④appliation 

( )