サーブレット+JSPのシステムを作っています。
サーブレットはマルチスレッドなので、基本的にはローカル変数を使うようにと、いろいろなサイトで目にしました。
しかし、現存のソースコードはどれも冗長で、もっと整理できないものかと考えました。
例えば、各サーブレットで共通の処理は親クラスを作成してそちらで管理したいのですが、そうするとスレッドセーフではなくなってしまうのでしょうか。
たとえば、
/* 親クラス */ public class MYServlet extends HttpServlet { protected void showCommonError(String message) { session.setAttribute("message", message); response.sendRedirect("/error/"); } }
/* 子クラス */ public class SampleServlet extends MYServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { HttpSession session = request.getSession(); if (StringUtils.isEmpty(session.getAttribute("requiredAttribute"))) { showCommonError("requiredAttribute is Empty."); } }
このようにすると、意図した内容のmessageが親クラスに渡らなくなってしまうのでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/02/10 11:38