liguofeng29’s blog

個人勉強用ブログだっす。

Struts2 - Stack Context

<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
    <title>WELCOME</title>
</head>
<body>
    Value Stack:<br>
    ユーザ名:<s:property value="username"/><br>
    パスワード:<s:property value="password"/><br>

    Stack Context<br>
    ユーザ名(リクエストパラメータ):<s:property  value="#request.username"/><br>
    パスワード(リクエストパラメータ)<s:property  value="#request.password"/><br>

    <!-- debugタグを使い -->
    <s:debug />
</body>
</html>

f:id:liguofeng29:20160321214557p:plain

※要約

  1. Struts2はOGNL(Object Graph Navigation Language)を使いデータアクセスする
  2. Stack Context内にデータを保存し、#オブジェクト名でアクセスする
  3. Value StackはStack Contextのルートオブジェクトであり、#を使わずにアクセスできる。
  4. ActionインスタンスはValue Stack内に保存される。
  5. parameters, request, session, application, attrなど命名オブジェクトが存在する

※static access

<constant name="struts.ognl.allowStaticMethodAccess" value="true" />