如何在jsp中调用方法,帮帮我

时间:2015-04-13 08:59:35

标签: spring spring-mvc

@Repository
public class MenuDAOImpl implements MenuDAO {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public List<Menu> showMenus(String typemenu) {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Menu.class);
        criteria.add(Restrictions.ne("Id", 1));
        criteria.add(Restrictions.eq("Status", 1));
        criteria.add(Restrictions.eq("Menutype", typemenu));
        criteria.addOrder(Order.asc("Lft"));
        return criteria.list();
    }

}


public interface MenuService {

    public List<Menu> showMenus(String typemenu); 

}


@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDAO menuDAO;

    @Transactional
    public List<Menu> showMenus(String typemenu) {
        return menuDAO.showMenus(typemenu);
    }
}



<% List<Menu> listmenu = DefaultMenuBar.buildMenuBar("adminmenu");%>
  

显示java.lang.NullPointerException     com.dnict.spring3mvc.main.service.MenuServiceImpl.showMenus(MenuServiceImpl.java:90)     com.dnict.utilities.DefaultMenuBar.buildMenuBar(DefaultMenuBar.java:13)     org.apache.jsp.WEB_002dINF.layouts.admin_002dtiles.menu_jsp._jspService(menu_jsp.java:67)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:927)     org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:684)     org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:678)     org.apache.tiles.jsp.context.JspTilesRequestContext.include(JspTilesRequestContext.java:103)     org.apache.tiles.jsp.context.JspTilesRequestContext.dispatch(JspTilesRequestContext.java:96)     org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)     org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)     org.apache.tiles.renderer.impl.ChainedDelegateAttributeRenderer.write(ChainedDelegateAttributeRenderer.java:76)     org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:336)     org.apache.tiles.template.InsertAttributeModel.renderAttribute(InsertAttributeModel.java:210)     org.apache.tiles.template.InsertAttributeModel.end(InsertAttributeModel.java:126)     org.apache.tiles.jsp.taglib.InsertAttributeTag.doTag(InsertAttributeTag.java:311)     org.apache.jsp.WEB_002dINF.layouts.admin_002dtiles.baseLayout_jsp._jspx_meth_tiles_005finsertAttribute_005f1(baseLayout_jsp.java:252)     org.apache.jsp.WEB_002dINF.layouts.admin_002dtiles.baseLayout_jsp._jspService(baseLayout_jsp.java:174)     org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)     org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)     org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241)     org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:222)     org.apache.tiles.renderer.impl.TemplateAttributeRenderer.write(TemplateAttributeRenderer.java:44)     org.apache.tiles.renderer.impl.AbstractBaseAttributeRenderer.render(AbstractBaseAttributeRenderer.java:106)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:670)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:690)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:644)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:627)     org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:321)     org.springframework.web.servlet.view.tiles2.TilesView.renderMergedOutputModel(TilesView.java:124)     org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:264)     org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1208)     org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:992)     org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:939)     org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)     org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)     org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)     javax.servlet.http.HttpServlet.service(HttpServlet.java:621)     org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)     javax.servlet.http.HttpServlet.service(HttpServlet.java:722)     org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)     org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:330)     org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)     org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)     org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:125)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.access.channel.ChannelProcessingFilter.doFilter(ChannelProcessingFilter.java:144)     org.springframework.security.web.FilterChainProxy $ VirtualFilterChain.doFilter(FilterChainProxy.java:342)     org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)     org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)     org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)     org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)

1 个答案:

答案 0 :(得分:0)

试试这个;

WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
MySpringService srvObject = (MySpringService) wac.getBean("mySpringService");//mySpringService mean bean id of MySpringService 
List<myspringservice> lst= srvObject.listAll();

参考链接:

http://codexamples.blogspot.in/2010/05/how-to-access-spring-service-from.html

http://digitaljoel.nerd-herders.com/2010/11/01/accessing-spring-session-beans-in-jsp/