Forums: Open Discussion (Thread #21084)

セッション情報について (2008-12-26 14:42 by Anonymous #40827)

アクションフォームクラスでHttpServletRequest requestを取得して、セッション情報を置き換えると別の端末のセッション情報の同じkeyまで置き換わってしまいます。それって無いと思っていましたが...。どなたか知っている方いますか?

Reply to #40827×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-05 15:11 by hachihachi #40923)

現象が再現できるコードを載せていただけますか?
Reply to #40827

Reply to #40923×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-06 14:47 by Anonymous #40945)

public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);

if("AA/AAA".equals(mapping.getPathId)){
Uvo uvo = (Uvo) request.getSession().getAttribute("USER_VALUE_OBJECT");
uvo.setAAA(request.getSession().getAttribute("A"));
request.getSession().setAttribute("USER_VALUE_OBJECT", uvo);
}else if("BB/BBB".equals(mapping.getpathId)){
Uvo uvo = (Uvo) request.getSession().getAttribute("USER_VALUE_OBJECT");
uvo.setTest(request.getSession().getAttribute("B"));
request.getSession().setAttribute("USER_VALUE_OBJECT", uvo);
}
上記を2端末から同時に行った場合,sessionが後がちになります。
Reply to #40827

Reply to #40945×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-06 15:58 by kimumasa #40949)

手元の環境
Tomcat5.5.27
JavaSE 1.5.0.16
terasoluna-server4jweb-2.0.1.0
では起きませんでした。

※mapping.getPathIdではなく
 mapping.getPath()にして複数ブラウザから
 同時実行させました

本件はHTTPSessionの中のオブジェクトは
スレッドセーフでなない事から起きているように見えます。

HTTPSessionはAPサーバの実装依存のところがありますが
さすがにこの手のバグが残っている
可能性は低いと思いますので
UVOシングルトン(ないしそのフィールドがstatic)実装に
なっているのでは無いでしょうか?
Reply to #40945

Reply to #40949×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-06 17:29 by Anonymous #40953)

環境は
Tomcat5.5.25
JavaSE 1.5.0.13
です。
staticにはなっていませんでした。

すいません、上記のgetPath()の条件文はあまり関係なかったです。
URLからパラメータ(test=A)を追記して実行します。
※A端末はA、B端末はB

ちなみ、resetメソッドではなく、jspに記載すると問題は無かったです。
Reply to #40827

Reply to #40953×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-06 18:48 by hachihachi #40958)

>uvo.setAAA(request.getSession().getAttribute("A"));
>uvo.setTest(request.getSession().getAttribute("B"));

この辺がよくわからないのですが、このセッションに格納されている"A"や"B"はどこで設定しているのでしょうか?
Reply to #40827

Reply to #40958×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-06 19:51 by kimumasa #40959)

動作確認用のコードを貼り付けてしまいます。
再現できる状況と差異がありましたら
ご指摘頂ければと思います。

#要件が見えていないので外しているかもしれませんが
resetメソッドでやるべき処理のように見えていません。
RequestProcessorExを拡張するのが素直なように感じています。

===ActionForm===
package org.test;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionMapping;
import org.test.Uvo;

import jp.terasoluna.fw.web.struts.form.ValidatorActionFormEx;

public class TestForm extends ValidatorActionFormEx {

public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);

if ("/test".equals(mapping.getPath())) {
Uvo uvo = (Uvo) request.getSession().getAttribute(
"USER_VALUE_OBJECT");
uvo.setAAA(request.getSession().getAttribute("A"));
request.getSession().setAttribute("USER_VALUE_OBJECT", uvo);
} else if ("/test2".equals(mapping.getPath())) {
Uvo uvo = (Uvo) request.getSession().getAttribute(
"USER_VALUE_OBJECT");
uvo.setTest(request.getSession().getAttribute("B"));
request.getSession().setAttribute("USER_VALUE_OBJECT", uvo);
}
}

}
=== JSP1 ===
<%@ page contentType="text/html; charset=Windows-31J"%>
<%@ taglib uri="/struts-html" prefix="html"%>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-logic" prefix="logic"%>
<%@ taglib uri="/terasoluna-struts" prefix="ts"%>
<%@ taglib uri="/terasoluna" prefix="t"%>
<%@page import="org.test.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>-</title>
</head>
<body>
<%
Uvo uvo = new Uvo();
uvo.setFrom("wellcome");
session.setAttribute("USER_VALUE_OBJECT", uvo);
session.setAttribute("A", "messageA");
%>
<html:form action="/test.do">
<html:text property="userId" value="aaa"></html:text>
<html:submit>送信</html:submit>
</html:form>
</body>
</html:html>

===JSP2===
<%@ page contentType="text/html; charset=Windows-31J"%>
<%@ taglib uri="/struts-html" prefix="html"%>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-logic" prefix="logic"%>
<%@ taglib uri="/terasoluna-struts" prefix="ts"%>
<%@ taglib uri="/terasoluna" prefix="t"%>
<%@page import="org.test.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>-</title>
</head>
<body>
<%
Uvo uvo = new Uvo();
uvo.setFrom("wellcome2");
session.setAttribute("USER_VALUE_OBJECT", uvo);
session.setAttribute("B", "messageTest");
%>
<html:form action="/test2.do">
<html:text property="userId" value="test"></html:text>
<html:submit>送信</html:submit>
</html:form>
</body>
</html:html>

===JSP3===
<%@ page contentType="text/html; charset=Windows-31J"%>
<%@ taglib uri="/struts-html" prefix="html"%>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-logic" prefix="logic"%>
<%@ taglib uri="/terasoluna-struts" prefix="ts"%>
<%@ taglib uri="/terasoluna" prefix="t"%>
<%@page import="org.test.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>-</title>
</head>
<body>
<html:form action="/test.do">
<center>
<%
Uvo uvo = (Uvo) session.getAttribute("USER_VALUE_OBJECT");
out.print("Form:" + uvo.getFrom() + "<br>");
out.print("AAA:" + uvo.getAAA() + "<br>");
out.print("Test:" + uvo.getTest() + "<br>");
%>
</center>
</html:form>
</body>
</html:html>

=== struts-config.xml===
<action path="/welcome" parameter="/welcome.jsp"/>
<action path="/welcome2" parameter="/welcome2.jsp"/>

<action path="/test" parameter="/test.jsp" name="testForm" scope="session"/> <action path="/test2" parameter="/test.jsp" name="testForm" scope="session"/>

Reply to #40827

Reply to #40959×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-07 13:33 by Anonymous #40988)

本当に申し訳ありません。
お聞きしたいことは、resetを使用するとA端末とB端末のセッション情報が後がちなってしまう状態がでたので、その原因を知りたかったです。

画面は三段階です。
メニュー画面 → 呼び出し画面 → 結果画面

※A端末のURLに「?test=AA」(パラメータ)追記し開き、
B端末のURLに「?test=BB」追記し開いてください。


===ActionForm===

import org.test.Uvo;

import jp.terasoluna.fw.web.struts.form.ValidatorActionFormEx;

public class TestForm extends ValidatorActionFormEx {

public void reset(ActionMapping mapping, HttpServletRequest request) {
super.reset(mapping, request);

Uvo uvo = (Uvo) request.getSession().getAttribute("USER_VALUE_OBJECT");
uvo.setTest(request.getSession().getAttribute("test").toString());
request.getSession().setAttribute("USER_VALUE_OBJECT", uvo);
}
}

=== JSP1(メニュー) ===
<%@ page contentType="text/html; charset=Windows-31J"%>
<%@ taglib uri="/struts-html" prefix="html"%>
<%@ taglib uri="/struts-bean" prefix="bean"%>
<%@ taglib uri="/struts-logic" prefix="logic"%>
<%@ taglib uri="/terasoluna-struts" prefix="ts"%>
<%@ taglib uri="/terasoluna" prefix="t"%>
<%@page import="org.test.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=shift_jis">
<title>-</title>
</head>
<body>
<ul>
<html:link page="/YY.jsp" title="YY"></html:link>
</ul>
</body>
</html:html>
Reply to #40827

Reply to #40988×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: セッション情報について (2009-01-07 14:30 by kimumasa #40994)

お手数ですが、よく理解できないのですが・・・

・Uvoはどこでどうやってインスタンス化し、Sessionに入れているのでしょうか。
・YY.jspへの直接遷移ではTestForm#resetが呼び出されません。
 リンクのURLはYY.doで、YY.do?test=AAでresetメソッドを呼び出すという認識出会っていますでしょうか?
・> uvo.setTest(request.getSession().getAttribute("test").toString())
 ではなく
uvo.setTest(request.getParameter("test"))
 ではないでしょうか?(パラメータで渡すのですよね?)

出来れば再現できるJSP、Java、XMLを
全て提示して頂けると助かります。
Reply to #40988

Reply to #40994×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login