Results 1 to 3 of 3

Thread: <jsp:usebean> and applicationContext problem

  1. #1
    Join Date
    Jun 2006
    Posts
    5

    Default <jsp:usebean> and applicationContext problem

    Hii All

    We are porting our struts based system to spring. At the JSP level we used some application scope beans made available using the <jsp:useBean> tag previously. These beans use the unserlying services ( constants information)
    which are wired using appilcationContext XML's .

    Now the problem is when i bring the system up and hit the JSP I get a NullpointerException as the bean is unable to find the wired service instances.
    Is'nt the application context of spring and the container same ??
    Any suggestions on how to solve this problem

    Thanks in advance.

  2. #2
    Join Date
    Apr 2006
    Posts
    25

    Default

    I'd recommend accessing this type of constants information from a resource bundle, and not a constants type class wired as a Spring bean. Normally, this type of conversion would not be an overly time-consuming endeavor. Accessing the application context from the view layer in the way you are attempting to do so is not normally recommended. Nevertheless, a way to access Spring's ApplicationContext from a jsp would be:

    <% ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContex t(request.getSession().getServletContext()); %>

    Spring's ApplicationContext is not tied to the java servlet technology mechanisms, helping to explain why your attempts to directly access your 'wired' beans is failing. You could also use Spring's RequestContext from the jsp to access Spring's ApplicationContext.

  3. #3
    Join Date
    Jun 2006
    Posts
    5

    Default problem solved

    solved the problem..

    Made a PreAction which loads the wired instances of the beans in the application context.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •