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 6250093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:21:30+00:00 2026-05-24T13:21:30+00:00

I try to fetch values from servlet into my JSP, but it throws a

  • 0

I try to fetch values from servlet into my JSP, but it throws a NullPointerException or some other error.

This is the servlet which gets values from JSP:

buildingprofilerequest.java

package asset.management.arms.buildingprofilemodule;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sun.xml.internal.ws.client.SenderException;
/**
 * Servlet implementation class buildingprofilerequest
 */
public class buildingprofilerequest extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try{

            buildingservice building = new buildingservice();
            building.setBuilding_name(request.getParameter("combobox"));

            building = BuildingDAO.build(building);

            request.setAttribute("abcd", building);      


                 RequestDispatcher dispatcher =                  
                 getServletContext().getRequestDispatcher("/building_profile_details.jsp");

            dispatcher.include(request, response);

        }
    catch (Throwable theException)      
        {
             System.out.println(theException); 
        }

    }

My bean looks in brief like this:

buildingservice.java

package asset.management.arms.buildingprofilemodule;

public class buildingservice {

        private String building_name;

                public String getBuilding_name() {
            return building_name;
        }

        public void setBuilding_name(String newbuilding_name) {
            this.building_name = newbuilding_name;
        }

              //and has many more parameters and there getters and setters
        }

My other class is BuildingDAO.java, here all the calculations are done:

package asset.management.arms.buildingprofilemodule;

import java.sql.*;
import asset.management.arms.loginmodule.ConnectionManager;

public class BuildingDAO {
    static Connection currentCon = null;
    static ResultSet rs = null;  

    public static buildingservice build(buildingservice bean) {

           String building_name = bean.getBuilding_name(); 

           String searchQuery = "select * from buildings";
         try{
            //connect to DB 
            currentCon = ConnectionManager.getConnection();
             stmt=currentCon.createStatement();
             rs = stmt.executeQuery(searchQuery);           

             while(rs.next()){

            //retreiving building parameters from database   
             String buildingname = rs.getString("building_name");
             String buildingnumber = rs.getString("building_number");
             int buildarea = rs.getInt("build_area");

                  //setting building parameters
                 bean.setBuilding_name(buildingname);
                 bean.setBuilding_number(buildingnumber);
                 bean.setBuild_area(buildarea);
                 bean.setBuilt_year(builtyear);
            catch (Exception ex) 
          {
             System.out.println(" " + ex);
          } 

            finally 
          {
             if (rs != null)    {
                try {
                   rs.close();
                } catch (Exception e) {}
                   rs = null;
                }

             if (stmt != null) {
                try {
                   stmt.close();
                } catch (Exception e) {}
                   stmt = null;
                }

             if (currentCon != null) {
                try {
                   currentCon.close();
                } catch (Exception e) {
                }

                currentCon = null;
             }
          }

        return bean;
    }

}

My JSP is this:

building_profile_details.jsp

<%@ page language="java" contentType="text/html; charset=iso-8859-1"
    pageEncoding="ISO-8859-1" import="asset.management.arms.buildingprofilemodule.buildingservice"%>

<%  buildingservice hello = (buildingservice) request.getAttribute("abcd"); %>

<table width="1150" height="176" border="1" align="center" bordercolor="lightslategray">
      <tr>
        <td width="107"><div align="center"><b>Building Number</b> </div></td>
        <td width="325"><div align="center"><b>Building Name </b></div></td>
        <td width="70"><div align="center"><b>area</b></div></td>
        <td width="146"><div align="center"><b>built year</b></div></td> 
          </tr>

<tr>
    <td><div align="center"><%=hello.getBuilding_number()%></div></td>
    <td><div align="center"><%= hello.getBuilding_name()%></div></td>
<td><div align="center"><%=hello.getBuild_area()%></div></td>
 <td><div align="center"><%= hello.getBuilt_year()%></div></td>
</tr>
</table>

In the JSP I even tried other ways like:

<jsp:useBean id="hello" class="asset.management.arms.buildingprofilemodule.buildingservice">

and then in individual blocks of table:

<jsp:getProperty name="hello" name="building_name">

But nothing works, it throws error which says

org.apache.jasper.JasperException: Exception in JSP: /building_profile_details.jsp:82

82:     <td><div align="center"><%=hello.getBuilding_number()%></div></td>

and similarly for other lines.

How is this caused and how can I solve this?

  • 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-05-24T13:21:30+00:00Added an answer on May 24, 2026 at 1:21 pm

    In your servlet, replace

    dispatcher.include(request, response);
    

    by

    dispatcher.forward(request, response);
    

    In your JSP, remove

    <%  buildingservice hello = (buildingservice) request.getAttribute("abcd"); %>
    

    and replace

    <td><div align="center"><%=hello.getBuilding_number()%></div></td>
    <td><div align="center"><%= hello.getBuilding_name()%></div></td>
    <td><div align="center"><%=hello.getBuild_area()%></div></td>
    <td><div align="center"><%= hello.getBuilt_year()%></div></td>
    

    by

    <td><div align="center">${abcd.building_number}</div></td>
    <td><div align="center">${abcd.building_name}</div></td>
    <td><div align="center">${abcd.build_area}</div></td>
    <td><div align="center">${abcd.built_year}</div></td>
    

    See also:

    • Our Servlets wiki page
    • Our JSP wiki page
    • Our EL wiki page

    There are by the way many other serious problems in your code, but they are not related to the current concrete problem. I’ll however try to sum the most important ones up:

    • Code holds DB resources as static variables. This is a major threadsafety problem!
    • Code does not handle exceptions in a sensible manner. This is not developer nor user friendly.
    • Code does not respect Java naming conventions. This leads to developer confusion and maintainability problems.
    • Code (particularly the buildingservice and BuildingDAO) uses very odd approaches/patterns/flows. It look like to be written by a procedural programmer who doesn’t understand Object Oriented Programming concepts.
    • JSP uses scriptlets which is discouraged since 2003. Keep yourself up to date. Java code belongs in Java classes and JSP should only contain HTML, JSP tags and EL.
    • HTML uses deprecated attributes. Keep yourself up to date. Learn CSS.

    Work on that as well.

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

Sidebar

Related Questions

I am receiving values from other activities and with these values try to fetch
I am making an android database app in which when i fetch values from
Im trying to pass some values into a text box from a child page
I'm having some issues returning values from a server with php + mysql. This
I use kohana and when you try to fetch data from database it returns
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
in my application i try to fetch users location but it always 0.0 for
I am having difficulty to explain this problem, but I will try anyway. I
I have made a generic handler (.ashx) to fetch some database values using jquery
I am trying to retrieve values from Json Object but getting Exception.I am trying

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.