0

背景として、JBoss AS 7 と EJB を使用しています。最初に接続してセッションIDを取得するときに、erraiメッセージバスを使用してクライアントからサーバーにメッセージを送信し、後でリクエストを作成してサーバーに特定のクライアントに応答させることができます。

どうすればこれを行うことができますか?どうにかして HttpSession オブジェクトのサーバー側を注入できますか? 私はこれに非常に慣れていないので、ご容赦ください。漠然としすぎている場合はお知らせください。詳しく説明します。

4

2 に答える 2

0
// the following variable is in the Http servlet service() method arguments
// only shown here this way to demonstrate the process
javax.servlet.http.HttpServletRequest serviceRequest;
javax.servlet.http.HttpServletResponse serviceResp; // addCookie()
javax.servlet.http.HttpSession cecil;
javax.servlet.http.Cookie[] reqCk;


// "(boolean overload) "true" creates the session" or call the other overload version method with no argument 
// to retrieve the session getSession() "the server container stores and creates sessions"
// false in that version is to avoid bothering for a session to cut down uneeded processing


cecil = serviceRequest.getSession();//creates a session if it does not have one


String httpSession_ID = cecil.getID();


if((reqCk = serviceRequest.getCookies()) == null){

// perhaps create a cookie here using "new class "
// cookiePiece = new javax.servlet.http.Cookie("COOKIENAME",....); ....YOU MUST LEARN THE COOKIE PARTS WRITING RULES FOR BROWSER COOKIES !!! ; ; ;
serviceResp.addCookie(cookiePiece); // now is on the servers array "reqCk"

}else{

// process the cookie here using javax.servlet.http.Cookie methods

}

データを格納および取得するその他の方法は、セッション スコープの JSP または JSF Beanです。

于 2013-07-29T03:27:59.490 に答える