0

私はサーブレットを使用しており、ADF で JSFUtils.resolveExpression("#{sessioncontext}") メソッドを使用してセッション コンテキストを取得しようとしていますが、Null ポインター例外が発生しています。上記の使用方法の何が問題なのか、サーブレットでセッションコンテキストを取得する別の方法はありますか?

ありがとう、

編集: 以下のコードを見つけてください。

public class MyServlet extends HttpServlet {


public final void init(final ServletConfig config) throws ServletException {
    super.init(config);
}

public void doGet(HttpServletRequest request,
                HttpServletResponse response)
        throws ServletException, IOException
{
    response.setContentType("text/html");
  PrintWriter out = response.getWriter(); 
 SessionContext session = (SessionContext) JSFUtils.resolveExpression("#{sessioncontext}");
  //more code below

  }
}
4

2 に答える 2

-1

上記のコード行を以下のコードに置き換えたところ、正常に動作しました:) Null PointerをスローしていたFacesContextにアクセスできませんでした

FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext == null) {
        FacesContextFactory contextFactory =
            (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
        LifecycleFactory lifecycleFactory =
            (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
        Lifecycle lifecycle =
            lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
        facesContext =
                contextFactory.getFacesContext(request.getSession().getServletContext(),
                                               request, response,
                                               lifecycle);
        // Below is an Inner Class which extends FacesContext to use its below protected method
        AbstractInnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
    }

今私は FacesContext を持っているので、resolveExpression メソッドで使用されるのと同じロジックを使用して、これから簡単に SessionContext を取得できます:) (イェーイ!!!)

于 2013-10-02T15:25:40.720 に答える