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

  • Home
  • SEARCH
  • 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 9236229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:14:29+00:00 2026-06-18T07:14:29+00:00

This is my program for getting an ArrayList which contain bean-object from the servlet

  • 0

This is my program for getting an ArrayList which contain bean-object from the servlet and showing its content in jsp using jstl tag . After i run the program no result is shown. Please look to my code and help me find the error. I am new to jstl.

servlet code

package com.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.servlet.mybean;
@WebServlet("/Bean")
public class Bean extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Bean() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        mybean mybean_obj = new mybean();
        ArrayList<mybean> obj=new ArrayList<mybean>();

        mybean_obj.id=100;
        mybean_obj.name="vishal";
        mybean_obj.roll=1225;

        mybean mybean_obj1 = new mybean();

        mybean_obj1.id=101;
        mybean_obj1.name="anand";
        mybean_obj1.roll=1226;

        mybean mybean_obj2 = new mybean();

        mybean_obj2.id=102;
        mybean_obj2.name="google";
        mybean_obj2.roll=1557;

        mybean mybean_obj3 = new mybean();

        mybean_obj3.id=103;
        mybean_obj3.name="yahoo";
        mybean_obj3.roll=1558;

        obj.add(mybean_obj);
        obj.add(mybean_obj1);
        obj.add(mybean_obj2);
        obj.add(mybean_obj3);
        HttpSession session = request.getSession();
        session.setAttribute("mybean", obj);
        request.setAttribute("mybean", obj);
        RequestDispatcher fwd = request.getRequestDispatcher("encodeUrl.jsp");
        fwd.forward(request, response);

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

jsp page

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
        <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Encode URL </title>
</head>
<body>
 <c:forEach var="start" items="${sessionScope.mybean}">
      ${sessionScope.start.id}<br/>${sessionScope.start.roll }<br/>${sessiontScope.start.name }<hr/>
  </c:forEach>
</body>
</html>

i am calling servlet from home page and from servlet the request is forwarded to final jsp page whose code is above.

  • 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-18T07:14:31+00:00Added an answer on June 18, 2026 at 7:14 am

    Rewrite your code like this :

    <c:forEach var="start" items="${sessionScope.mybean}">
          ${start.id}<br/>${start.roll }<br/>${start.name }<hr/>
      </c:forEach>
    

    the var=”start” creates a local variable named start representing the current item. You can use that within the forEach statement. (there is no need to prefix it with sessionScope as there is no sessionScope based bean called start)

    Some other tips for your code :

    MyBean bean = new MyBean(); // classes start with an uppercase and use CamelCasing.
    List<mybean> beans=new ArrayList<MyBean>(); // program against the list interface.
    bean.setId(100); // use accessor methods instead of accessing variables directly.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I am running this program I am getting warning array subscript has type
I am getting ERROR when I am running this program at the line static
Well, I was trying to fix this program, and I keep getting the errors
Im trying to use Date Formatters (NSDateFormatter), but I keep getting this error: Program
Ok, first off, I didn't program this page with frames! I'll be getting rid
I am making this assignment in my program and I am getting the warning
I'm having trouble getting a sample program to link correctly (in this case against
I am trying to run a program and SOMETIMES I'm getting this error when
I am doing a minesweeper program for school, but i keep getting this error
I am getting this error when I try to run my program Exception in

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.