顯示具有 JSP 標籤的文章。 顯示所有文章
顯示具有 JSP 標籤的文章。 顯示所有文章

2013年9月2日 星期一

[Web] Note

disable
設為 true 欄位值不會被送出




< form:input path= "name" value = "${name}" ${xxx ?  "disabled='disbaled'" : ""}  />




value
沒有 value 不會觸發 setXXX 用 getParameter 會取到 null
value="" 會送空的
value 會送null


url mapping
"/{" + ATTRIBUTE_PACKAGE_NAME + ":.+}"


htmlEscape
true = render(escape?) to html
false = show the text

[Web] enum form value

Error

<form:radiobutton value="enum type object">

post 時發生 mistypematched exception



Solution

<form:radiobutton value="enum.toString">

因為 enum 會被 toString


http param string <-> enum name


2012年2月15日 星期三

[J2EE] Get values from server on Page

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>






 

 

"${pageContext.request.contextPath}/home"  



"${person.dog.name}"

<%= (Person) request.getAttribute("person").getDog().getName() %>

<%
    String name = request.getAttribute("person").getDog().getName();
    request.setAttributes("name", name);
%>
// => "${name}"


// => "${name}"



"${javax.servlet.forward.servlet_path}"

2011年10月9日 星期日

[JSP] type of Map's key

Map autoboxing uses Integer as key; JSP EL uses Long.

That's why the following codes are not working, if key defined as "1":



    ....





2011年10月1日 星期六

[J2EE] note

* submit 後將 form 中欄位的值送到 server

* server site 也做檢查是避免惡意人士 造假頁面試圖躲過頁面上的檢查 然後 submit 到我們的 server 的 action url

* jsp 會被 server compiler,html tag js 應視為頁面上固定死的東西(字串) ,所以 java 穿插在其中的 code 應以 compiler 後的值來看,而不是以 java code 的角度來看。



2011年9月18日 星期日

[WEB] Tile, JSTL, JS syntax in HTML





${status.count}


 colspan="2">



* Tile 的 attribute 在 HTML 中可透過 getAttribute 取得,ex:

<tiles:insertAttribute name="title" />





* 視 js 為 .txt







2011年9月4日 星期日

API Release Version

[Java]
  • for each
    • from 1.5
  • @Override
    • from 1.5
    • 但在 1.5 不支援 interface 使用,因此必須使用 1.6。
    • 20120615
      • 1.7 也無支援

[JSP]
  • EL
    • from 2.0


* Reference
- 关于解决Java @Override的问题


2011年3月15日 星期二

[JSP] Introduction

* Directive
  • <%@              %>
  • 使用指令元素include來包括其它網頁內容時,會在轉譯時期就決定轉譯後的Servlet內容,是一種靜態的指定方式。
  • 標籤的使用,則是執行時期動態將別的網頁包括進來進行回應的方式,使用的網頁與被包括的網頁,各自都生成一個獨立的Servlet。

* 宣告、Scriptlet 與運算式元素
  • Declare: <%!      %>
  • Scriptlet: <%       %>
  • Expression: <%=       %>
  • 容器預設會使用同一個Servlet實例來服務不同使用者的請求,每個請求是一個執行緒,而<%!與%>間宣告的變數對應至類別變數成員,因此會有執行緒共用存取的問題。
  • <%與%>之間所包括的內容,將被轉譯為Servlet原始碼_jspService()方法中的內容。注意!運算式元素中不用加上分號(;)。這個運算式元素在轉譯為Servlet之後,會在_jspService()中產生以下的陳述句:out.print(new Date());

* JSP 生命週期
  • 注意到_jspInit()、_jspDestroy()與_jspService()方法名稱上有個底線,表示這些方法是由容器轉譯時維護,你不應該重新定義這些方法。如果想要作些JSP初始化或收尾動作,則應定義jspInit()或jspDestroy()方法。

* 深入 <jsp:usebean>、<jsp:setproperty> 與 <jsp:getproperty>
  • 如果你使用標籤時沒有指定scope,則預設「」在page範圍中尋找JavaBean,找不到就建立新的JavaBean物件(不會再到request、session與application中尋找)。


* Reference
- 語言技術:Servlet/JSP Gossip

2011年2月24日 星期四

[JSP] Session and Cookie

Session


* Passing session specific data through the application object is not safe.

* Different sessions could override each other.

* When the browser is closed and started again, a new session object is created but the application is still the same.

* Flow:
  1. When the first request comes from a browser on a new host, the server makes the beginning of a new session, and assigns a new session ID. 
  2. The session ID will be then send to the browser as cookie. 
  3. The browser will remember this ID, and send the ID back to the server in the subsequent requests. 
  4. When the server receives a request with session ID in them, it knows this is a continuation of an existing session.When the server receives a request from a browser on a new host (request without a session ID), the server not only creates a new session ID, it also creates a new session object associated with the session ID. 
* If there is no subsequent request coming back for a long time for a particular session ID, that session will be timed out. After the session has been timed out, if the browser comes back again with the associated session ID, the server will give an invalid session error.


Cookie


Cookie: A small amount of information sent by a Web server to a Web browser, saved by the browser, and sent back to the server later. 


* Cookies are transmitted inside the HTTP header.

* C
ookies are actually saved to the hard disk of Web browser user's machines. 

If I keep clicking the refresh button, more and more cookies would be added to the request and response. But there is a limit. The browser will only take up to 20 cookies from one Web server.


* Reference
JSP and JSTL Tutorials - Herong's Tutorial Notes - JSP Sessions and Debugging
JSP and JSTL Tutorials - Herong's Tutorial Notes - Using Cookies

2011年2月22日 星期二

[JSP] JavaServer Pages

* Is a technology, not a language.


* To put dynamic data into a Web document with Java statements embedded in special HTML tags.


The embedded Java statements will be executed by the JSP enabled Web server, not by the Web browser.


There are two key processes involved in serving a JSP page:
  • Compilation: A JSP page must be compiled into a Java Servlet class, before it can be executed. The server can compile a JSP page in real-time when the page is requested for the first time, if the page is not pre-compiled.
  • Execution: When a JSP page is requested, its compiled class will be executed on the server. The server will send back the output of the execution, not the content of the JSP page.

* Example for hello.jspWhat happened here was that Tomcat, the JSP Web server, has translated hello.jsp into hello_jsp.java, and compiled it to hello_jsp.class.

The Java file, hello_jsp.java, shows that:
  • hello_jsp is a sub class of org.apache.jasper.runtime.HttpJspBase, which is a sub class of javax.servlet.http.HttpServlet.
  • The important method in hello_jsp is _jspService() with two objects listed as parameters: one represents the Servlet request, and the other represents the Servlet response.
  • The static content of hello.jsp is translated into out.write() statements.
  • The embedded Java statement in hello.jsp is copied directly.

JSP page is served by the JSP Web server by executing the JSP Servlet Java class translated from the JSP page.


Java statements embedded in JSP pages will translated into _jspService() method of a special Servlet class.

pre-defined objects ready for the embedded Java statements:
  • out: The output stream to collect dynamic data to be mixed into the final Web document.
  • this: The instance of the special Servlet class.
  • request: An HttpServletRequest object representing the request received from the Web browser.
  • response: An HttpServletResponse object representing the response to be delivered back to the Web browser.
  • session: An HttpSession object representing the concept of linking multiple trips of requests and response into a single process unit.
  • application: A ServletContext object representing the concept of grouping Servlets into a single application.

A new session will be established, if this JSP page is requested for the first time. Subsequent requests will share the same session. 

session: A object provided by the JSP server to hold information and methods common to all JSP pages running under one session. The session object must be an instance of a class that implements the javax.servlet.http.HttpSession interface defined by the J2EE specification. 


* Reference
JavaServer Pages (JSP)
Execution Context

2011年1月23日 星期日

Java Server Pages

.經Java平台技術 主要用來產生Dynamic Web constent 包括HTML DHTML XHTML 和XML

.Dynamic Web 技術標準似ASP PHP ...etc

.HTML 中加入Java片段(Scriptlet)和JSP標籤=JSP網頁

.Servlet/JSP container 收到client 發出的request 首先執行其中的程式片段 然後將執行結果以HTML 格式回應給客戶端

.其中程式片段可是:操作資料庫 重新定向網頁 發送email,etc

.所有程式操作都在Server執行 網路上傳送給Client的僅是得到的結果 與client的瀏覽器無關 因此JSP稱為Server-Side Language

.是類似於ASP的嵌入型scripting Language

.當JSP 被轉譯成Servlet時內容主要包含三部份:
-- _jspInit(): 當JSP網頁一開始執行時 最先執行此方法 因此我們通常會把初始化的工作寫在此方法中
-- _jspDwstroy(): JSP網頁最後執行的方法
-- _jspService(): JSP網頁最主要的程式都是在此方法

.JSP網頁主要可以分為:
-- Template Data: JSP container 不處理的部份 ex: HTML的內容 會直接傳送到Client 執行
-- Elements: 需經JSP container處理 而大部份elements都是以XML做為語法基礎 並且大小寫必須一致