Announcement Announcement Module
No announcement yet.
<jsp:usebean> and applicationContext problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • <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
    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
      problem solved

      solved the problem..

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