Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8405741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:54:43+00:00 2026-06-09T22:54:43+00:00

I am writing a jsp page that uses a scriptlet to call a method

  • 0

I am writing a jsp page that uses a scriptlet to call a method from a controller, which uses a method from a DAO, which performs a named query stored in a model corresponding to that DAO. I want this controller method to return an ArrayList which I can iterate through to retrieve its values to display on the page.
When the jsp gets to the method call, it gives me an NPE at the controller method, specifically on the line which would call the query method. What’s more vexing is that I call a similar method earlier on the page and get no exceptions there. My group has been using a Spring MVC framework with hibernate to handle our mapping.
I’ve tried to remove the non-essential parts of the code while leaving in things that might point to the solution. Let me know if you need more information and I will update as soon as possible.
(I plan to learn to avoid scriptlets in the future, as all the questions I’ve read so far tell me to avoid them.)
Here’s the code:
ReportingController method:

public ArrayList<String> weekWorkPrints(User user, CurrentWeek week) {
    ArrayList<UserTime> timeList = userTimeDao
            .getPunchesForUserAscendingByTime(user);
    ArrayList<String> prints = new ArrayList<String>();
    prints.add(utc.convertPeriodToPrint(utc.timeWorkedForADay(
            week.getSunday(), timeList)));
    return prints;
}

UserTimeDao method calling a query:

@SuppressWarnings("unchecked")
@Transactional
public ArrayList<UserTime> getPunchesForUserAscendingByTime(User passedUser) {

    Query loginQuery = em
            .createNamedQuery("fetchAllUserTimesForUserAscend");
    loginQuery.setParameter("user", passedUser);

    return (ArrayList<UserTime>) loginQuery.getResultList();
}

Named Query within UserTime model:

    @NamedQueries({
    @NamedQuery(name = "fetchAllUserTimes", query = "SELECT ut FROM UserTime ut"),
    @NamedQuery(name = "fetchAllUserTimesForUserDesc", query = "SELECT ut FROM UserTime ut WHERE ut.user = :user ORDER BY ut.userClockIn DESC"),
    @NamedQuery(name = "fetchAllUserTimesForUserAscend", query = "SELECT ut FROM UserTime ut WHERE ut.user = :user ORDER BY ut.userClockIn")})

JSP:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page import="models.*"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="models.*"%>
<%@page import="java.util.ArrayList"%>
<%@page import="controllers.ReportingController"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="userDao" class="daos.UserDao" scope="request" />
<jsp:useBean id="reportControl" class="controllers.ReportingController"
scope="request" />
<jsp:useBean id="currentWeekControl"
class="controllers.CurrentWeekController" scope="session" />
<jsp:useBean id="userTimeDao" class="daos.UserTimeDao" scope="request" />
<html>
<head>

<link rel="stylesheet" type="text/css" href="css/global.css" />
<link rel="stylesheet" type="text/css" href="css/reporting.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Administrator - Reporting</title>
</head>
<body>
<div id="wrapper">
    <div id="header">
        <h1>Administrator Home</h1>
        <%
            User loginUser = (User) session.getAttribute("loginUser");
        %>
        <p>
            Welcome,
            <%=loginUser.getUserName()%>!
        </p>
    </div>
<!-- ---- -->
                <table id="loggedTimeTable">
                    <%
                        CurrentWeek currentWeek = (CurrentWeek) session
                                .getAttribute("currentWeek");
                    %>
                    <!-- --- -->
                    <%
                        for (User iteratedUser : userDao.getAlphabeticalUsers()) {
                            ArrayList<String> weekPrintouts = reportControl.weekWorkPrints(
                                    iteratedUser, currentWeek);
                    %>
                    <tr>
                        <td><%=iteratedUser.getLastName()%>, <%=iteratedUser.getFirstName()%>
                        </td>
                        <td><%=weekPrintouts.get(0)%></td>
                    </tr>
                    <%
                        }
                    %>
                </table>

The Null Pointer Exception:

2012-08-19 21:21:02.315::WARN:  Nested in org.apache.jasper.JasperException: java.lang.NullPointerException: java.lang.NullPointerException
    at controllers.ReportingController.weekWorkPrints(ReportingController.java:106)
    at org.apache.jsp.jsp_002dpages.Reporting_jsp._jspService(org.apache.jsp.jsp_002dpages.Reporting_jsp:196)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:285)
    at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
    at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:238)
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1047)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
    at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:54:44+00:00Added an answer on June 9, 2026 at 10:54 pm

    Your problem is that your useBean for reportControl is simply creating a brand new ReportingController, which does not have the UserDao injected.

    What you are trying to do simply won’t work in Spring MVC, and nor should it. The objective of MVC is to separate the Model, View and Controller, but you are trying to create an instance of a controller inside a view.

    Instead, the controller method you have that returns the JSP name should first call your weekWorkPrints method and put the returned List in the Model so that the JSP can iterate through it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a web application that uses a JSP usebean tag in the
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
I am writing a jsp page, in which I want to determine the character
I am new to JSP/Servlets/MVC and am writing a JSP page (using Servlets and
I writing a JSP program that needs to react on an existing program. It
I'm writing a JSP that sometimes needs to format a Java Date that comes
Writing htaccess that allows me to remove index.php from the URL can confuse search
I am creating one jsp page in which I read in a text file,
I have a JSP page that renders a block of HTML. In normal usage,
I want to write reusable code that takes an HTML table from a JSP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.