私はStruts2フレームワークを使用しています。JSP ページの Action クラスの静的属性の値を取得できない理由がわかりません。私のコードでは、私が意味する静的属性は :nbreAppelAction
です。その結果、メソッドにマップされたアクションaa
のすべての呼び出しを取得します。初めて開いたときに 0 を取得できません。stayIndexAction
execute()
index.jsp
これが Action クラスです:
public class UserAction extends ActionSupport{
private static int nbreAppelAction = 0;
public String execute(){
utilisateur = new User();
nbreAppelAction++;
return SUCCESS;
}
public static int getNbreAppelAction() {
return nbreAppelAction;
}
public static void setNbreAppelAction(int nbreAppelAction) {
UserAction.nbreAppelAction = nbreAppelAction;
}
}
ここでは index.jsp です:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<p>
<a href="<s:url action='stayIndexAction' />" >Stay in index.jsp </a>
</p>
<p>a<s:property value="nbreAppelAction" />a</p>
</body>
</html>