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

2014年1月27日 星期一

[Web] meta X-UA-Compatible

<meta http-equiv="X-UA-Compatible" content="....." />

指定 render 的模式

content 內填入要使用的模式 可使用多個用逗號分開


. 標準模式:
IE=9; IE=8; IE=7...

. 模擬模式:
IE=EmulateIE9; IE=EmulateIE8; IE=EmulateIE7....

. 什麼版本 IE 就用什麼版本的標準模式:
IE=edge

. 強制 IE 使用 Google Chrome Frame:
chrome=1



Google Chrome Frame
  • IE plugin,可在 IE 中模擬 Chrome
  • 目前支援 IE 6、IE 7、IE 8、IE9


* Reference
. X-UA-Compatible設置IE兼容模式
. 在老 IE 中使用 Google Chrome Frame 超速新引擎瀏覽網頁(測試心得)
. Google Chrome Frame

2014年1月20日 星期一

[Java] Entity, POJO and DAO

Entity
對應 DB 的 object

POJO plain ordinary java object
不具備任何用途 用於不同地方 就是該角色

DAO data access object
訪問數據庫方法的 interface


2014年1月7日 星期二

[J2EE] JCA and cglib

J2EE Connector Architecture (JCA)
A resource manager integration API whose goal is to standardize access to non-relational resources in the same way the JDBC API standardized access to relational data.

cglib (Code Generation Library)
Used to extend JAVA classes and implements interfaces at runtime.


* Reference
- Chapter 7. Connectors on JBoss
- cglib

2014年1月6日 星期一

[J2EE] web.xml

/WEB-INF/web.xml

The deployment descriptor file describes how to deploy a web application in a servlet container such as Tomcat..


What are web.xml doing:
  • To determine how URLs map to servlets.
  • Which URLs require authentication.
  • Describes the classes, resources and configuration of the application and how the web server.


* Reference
- Web.xml
- The Deployment Descriptor: web.xml
- web.xml - DTD and XSD

2014年1月2日 星期四

[Web] attribute 命名中包含句點

model.put("aaa.bbb", "xxx");

在 jsp 中用 ${aaa.bbb} 不會顯示任何東西 會被視為 bbb 是 class aaa 中的 attribute

必須要寫成

${requestScope['aaa.bbb']}


* Reference
- Dots in attribute names

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

2012年2月16日 星期四

[Web] 新增資料處理

分頁會共用 session (Ref: [Web] session ID with browser)

所以顯示頁面時 把 Object(ex: Token) 放入 session 且將 Object 的 key 傳給頁面

model.put(ATTRIBUTE_TOKEN, token.getKey);
session.setAttribute(token.getKey(), token);

頁面 submit 時將 key 帶在路徑上

然後便能由 key 取出 session 中相對應的 token

藉此區別不同 tab 間的新增資料

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年11月7日 星期一

[Web] session ID with browser

若要分開 session ID
  • 最快的處理方式
    • 啟動兩個不同的瀏覽器。
  • 如果要同個瀏覽器,則
    • IE 可以建立捷徑 "C:\Program Files\Internet Explorer\iexplore.exe" -nomerge
    • FF 可以 "C:\Program Files\Mozilla Firefox\firefox.exe" -p -no-remote


下面把幾個常用瀏覽器的 session 管理方式列一下:
  • IE
    • IE6
      • session 不共享。
    • IE7
      • 不同 window,session 不共享。
      • 同一個 window 不同 tab ,session 共享。
    • IE8
      • 不同 window,session 共享。
      • 同一個 window 不同 tab,session 共享。
  • Firefox
    • session 共享。
  • Chrome
    • session共享。

2011年10月16日 星期日

[Security] SSL and HTTPS

[SSL]
  • Secure Socket Layer (安全套接層)。
  • 運行在TCP/IP層之上、應用層之下,與其繼任者傳輸層安全(TLS)是在網絡上為應用程序提供加密數據通道
  • 是網頁伺服器和瀏覽器之間以加解密方式溝通的安全技術標準,這個溝通過程確保了所有在伺服器與瀏覽器之間通過資料的私密性與完整性。
  • 採用了RC4、MD5以及RSA等加密算法。

Used for...
  • 確保 client 和 server 間的認證(網站身份認證)。
    • 因為 www 上充斥著假網站(釣魚網站)來騙取帳密,所以要驗證對方是真的。
  • 加密傳送資料,以防中途被竊取。
  • 維護數據的完整性,防範數據在傳送過程中被改變。

Process
  • 當瀏覽器端與 WWW 伺服器端同時支援 SSL 的傳輸協定時,在連線階段 SSL 同步確認 client 和 server,瀏覽器與伺服器就會產生那把的金鑰。
  • 產生金鑰後就能夠利用瀏覽器來傳送與接收加密過的重要資料啦。
  • 要注意的是,在某些很舊的瀏覽器上面是不支援 SSL 的。
  • Steps:
  1. Client request for server so start a new session. 告知伺服器端本身可實現的算法列表和其他一些需要的資訊。  
  2. Server 根據 client 的訊息確定是否要生成新的主密鑰,如果需要則 server 在 response 中包含生成主密鑰所需的資訊(資訊內包含身分及公鑰)。  
  3. client 根據收到的 response,產生一個密鑰,並用 server 的公鑰加密後傳給 server。(client 會自動的分析此證書,並根據不同版本的 browser,產生 40 位或 128 位的 session private key,用於加密傳送訊息。
  4. server 再用自己得私鑰解密得到 client 傳來的私鑰,並以私鑰加密要回傳的訊息,以讓 client 認證 server。




Problem
  • 那把 Public key 是伺服器產生且任何人都能取得的! ex:
    • 如果你不小心在釣魚網站輸入帳密,因為公鑰是誰都能拿到的,所以你的帳密還是被竊取,所以這時就需要第三方公正單位。

憑證
  • 可分為兩種:
    • 最低 40位和 128位 (private key 的長度,越長越不容破解)證書。
    • 最低 40位 server 證書在建立 session 時,根據 browser 版本不同,兩種都可以產生;而最低 128位 server 證書不受 browser 版本限制可以產生 128位以上的 private key,無論是 IE 或 Netscape,需要十年才能破解。
  • 一份 SSL 證書包含一個公鑰和一個私鑰。
    • 公鑰用於加密信息,私鑰用於解譯加密的信息。

CA
  • Certification Authority,認證中心。
  • 就是一個公認的公正單位,你可以自行產生一把金鑰且製作出必要的憑證資料並向 CA 單位註冊 (要錢的意思!),那麼當用戶端的瀏覽器在瀏覽時,該瀏覽器會主動的向 CA 單位確認該憑證是否為合法註冊過的:
    • 如果是的話,那麼該次連線才會建立。
    • 如果不是呢,那麼瀏覽器就會發出警告訊息, 告知使用者應避免建立連線啊。

Digital Signature
  • 在網路上﹐我們還可以使用“數位簽章(Digital Signature)”來進行身份確認。
  • 數位簽章可以說是一個獨一無二的數值﹐它由使用者的私有鍵值進行加密﹐然後利用公用鍵值進行確認
    • 若 public key 能通過驗證,那我們就肯定所對應的 private key 之正確性m
    • 否則,則可排除簽章所用的 private key 。
  • 換而言之,數位簽章兼具這兩種雙重屬性
    • 可確認性。
    • 不可抵賴性。


[HTTPS]
  • Secure Hyper Text Transfer Protocol (安全超文本傳輸協議)
  • Netscape公司相應開發了HTTPS協議並內置於其瀏覽器中。
  • 它是一個URI scheme(抽象識別字體系),https:URL表明它使用了HTTP,但HTTPS存在不同於HTTP的默認埠及一個加密/身份驗證層(在HTTP與TCP之間)。
  • HTTPS是以安全為目標的 HTTP通道,簡單講是HTTP的安全版,即HTTP下加入SSL層(因此加密的詳細內容請看SSL),實際上就是SSL over HTTP

HTTP vs. HTTPS

Advantages:
  • 所傳送的數據不容易被網絡黑客截獲和解密
    • 使用SSL在發送方把原始數據進行加密,然後在接受方進行解密,加密和解密需要發送方和接受方通過交換共知的密鑰來實現。

Disadvantages:
  • 耗效能
  • 加密和解密過程需要耗費系統大量的開銷,嚴重降低機器的性能,相關測試數據表明使用HTTPS協議傳輸數據的工作效率只有使用 HTTP協議傳輸的十分之一
    • 所以,我們只需對那些涉及機密數據如網上購物、交易付錢的交互處理、安全電子郵件等使用HTTPS協議,不需要用HTTPS 的地方,盡量不要用。

Overview


* Reference
- 小詞典: SSL和HTTPS
- 鳥哥的 Linux 私房菜 -- WWW 伺服器 Apache
- 加密網路封包鑑識設備
- 網路教學-資料加密
- SSL证书_百度百科
- https_百度百科
SSL和CA基礎知識
- 網站SSL加密原理簡介 ***

2011年10月15日 星期六

[Resources] not found for MessageSource

Error Message

main WARN org.springframework.context.support.ResourceBundleMessageSource.getResourceBundle(ResourceBundleMessageSource.java:223) - ResourceBundle [resource] not found for MessageSource: Can't find bundle for base name resource, locale en


Solution

因為找不到 properties file

一般應該要在 class 下

test case 中應和 configuration 放在同一層 否則要記得在 configuration 中要指定路徑。


[Note]

Sping test case 中指定 configuration 的 annotation:

@ContextConfiguration(locations = {"/applicationContext.xml"})


2011年10月9日 星期日

[J2EE] JUnit with weblogic

junit 沒通過 weblogic, run on J2SE


[J2EE] Log

Exception e

logger.error("test message", e);

log:
[2011...] main (...A) - test message
(......B)

A: log4j 裡設定的 pattern
B: e's trace stack

2011年10月2日 星期日

[Java] Java Message Service


* Definition
  • The Java Message Service (JMS) API,用來訪問消息收發系統,類似於JDBC(Java Database Connectivity)角色,只是是功能是訊息的傳遞。
  • Java Message Oriented Middleware (MOM) API for sending messages between two or more clients.
  • A messaging standard that allows application components based on the Java Enterprise Edition (JEE) to create, send, receive, and read messages.
  • 是由Sun與MOM廠商所共同制定的介面,定義了訊息的傳送、接收、頻道(Channel)、主題(Topic)、佇列(Queue)等標準介面。
  • 實作部份由廠商完成,Java開發人員只要學習標準API介面的使用,就可以利用各廠商的JMS支援系統來進行訊息傳送、接收等處理(您可以想像JDBC與資料庫廠商之間的關係)。
  • ex: 包括 IBM 的 MQSeries、BEA的 Weblogic JMS service和 Progress 的 SonicMQ。

* Advantages
Allows the communication between different components of a distributed application to be loosely coupled, reliable, and asynchronous.

* API
  • 頻道是用Destination這個介面來定義
    • 在訊息(Message)觀念中提及,訊息服務有兩種模式:
      • 出版-訂閱(Publish-Subscribe)
      • 點對點(Point-to-Point)
  • 頻道分為:
    • 主題
    • 佇列
  • Destination有兩個子介面Topic與Queue來分別代表。
    • 根據兩種模式的不同,ConnectionFactory有TopicConnectionFactory、QueueConnectionFactory兩個子介面。
  • 對於訊息產生者、訊息消費者的定義則分別為:
    • MessageProducer
    • MessageConsumer介面
    • 而在兩種模式下,分別有發佈 者(Publisher)、傳送者(Sender),以及訂閱者(Subscriber)、接收者(Receiver)。


* Usage
伺服端必須設定好ConnectionFactory以及Destination,並分別使用一個名稱向JNDI註冊,端點必須使用JNDI名稱查找ConnectionFactory及Destination,JMS端點取得ConnectionFactory,使用其與伺服端建立連線,連線以Connection介面定義。


[Message]
  • Messaging is a form of loosely coupled distributed communication, where in this context the term 'communication' can be understood as an exchange of messages between software components.
  • Message-oriented technologies attempt to relax tightly coupled communication (such as TCP network sockets, CORBA or RMI) by the introduction of an intermediary component.
  • The advantages of messaging include the:
    • Ability to integrate heterogeneous platforms.
    • Reduce system bottlenecks, increase scalability.
    • Respond more quickly to change.


[Message passing]
  • A form of communication used in parallel computing, object-oriented programming, and interprocess communication.
  • In this model, processes or objects can send and receive messages (comprising zero or more bytes, complex data structures, or even segments of code) to other processes. By waiting for messages, processes can also synchronize.
  • Message passing is the paradigm of communication where messages are sent from a sender to one or more recipients. Forms of messages include (remote) method invocation, signals, and data packets.



* Reference
Java Message Service - Wikipedia, the free encyclopedia
Message passing - Wikipedia, the free encyclopedia
簡介 Java Message Service
訊息(Message)觀念
JMS_百度百科

2011年10月1日 星期六

[J2EE] Apache and Weblogic


Weblogic default port is 7001.

Apache default port is 8001. (Or could refer /conf/httpd.conf "ServerName")

所以若是從 7001 連入則只能看見 weblogic 下的資源,從 8001 連進則能看見 apache 和 weblogic 的資源。


[J2EE] note

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

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

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



[J2EE] action, controller and servlet

action = controller = servlet

2011年9月12日 星期一

[J2EE] getParameter and getAttribute

* getParameter()
  • 資料會從 web client 傳到 web server,表示 HTTP 請求數據,get/post 的參數(For HTTP servlets, parameters are contained in the query string or posted form data. )。
  • app server 在分析你送上來的 request 頁面內容時,取得你設在表單或 URL 重定向時的值。
  • 只能接受 String。
  • ex: A.jsp 連到 B.jsp 時,B.jsp 可以透過 getParameter() 獲得請求參數。


* getAttribute()
  • 資料只會存在 web container,在具有轉發關係的 web 組件間共享,用來接受來自 servlet 的變數或 action,主要資料來至於server conainer 的記憶體,透過兩個方式設定:
  • container 自動加上去的一些 自訂request 資訊(javax.servlet.request.X509Certificate 等)。
  • setAttribute是 app server 把 object 放在該頁面所對應的空間,當頁面被 forward 到另一個頁面時, app server 會把這個空間的資訊複製到另一頁面所對應的空間中,所以getAttribute就能取得之前所設下的值。
  • 接受 type 是 Object。
  • 屬於 class HttpServletRequest。
  • ex: A.jsp forwaed到 B.jsp 時,可在 A.jsp 中先 setAttribute(),在 B.jsp 便可由 getAttribute 取得。


* Overview
  • 所以當使用get/post資料時,應該是用getParameter 而非 getAttribute ,若要在request (像是session)分享資訊(含Object),可以用getAttribute ,若要在兩個page 之間,理當要forward 才可以用getAttribute 共享,不然scope已經超過了..
  • ActionForm若僅只是要給forward使用的變數 , 可以用set/get Attribute 而少用session(效能)



* Reference
- request.getAttribute()和request.getParameter()的区别 - Java / Java EE
- JWorld@TW Java論壇 - Re:request的getParameter和getAttribute
- request.getAttribute()与request.getParameter() 方法区别_Struts_Java中文网
- request.getParameter和request.getAttribute之间的区别 - LL_java - 博客园

2011年8月27日 星期六

[Web] J2EE and struts

* J2EE
- 就有提供 interceptor
- request.setAttribute 傳送屬性到前端

* struts
- extends ActionSupport -> 可使用 setter/getter 處理屬性
- 可利用 interceptor 做類似 spring actionController 功能
- example:


<package name="packageName" namespace="/nameSpaceName">
    <default-interceptor-ref name="interceptorRef" />

    <action class="className" name="actionName">
        <result name="resultName">jspName</result>
    </action>
</package>


URL: /context/nameSpaceName/actionName.action
className: 此 action 所對應執行的 class (bean)

2011年5月15日 星期日

[Design] Validation on Business, Service, Web layer

對是否把校驗當作商業邏輯這個問題,存在著正和反兩種意見,而Spring提供的驗證模式(和資料綁定)的設計對這兩種意見都不排斥。特別是,校驗應該不應該被強制綁定在Web層,而且應該很容易本地化並且可以方便地加入新的驗證邏輯。基於上述的考慮,Spring提供了一個Validator介面。這是一個基礎的介面並且適用於應用程序的任何一個層面。



* Reference
- 5. Validation, Data Binding, and Type Conversion