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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:36:35+00:00 2026-06-09T11:36:35+00:00

First off thank you for reading! So I just learned JSP’s and Servlets this

  • 0

First off thank you for reading! So I just learned JSP’s and Servlets this week and this morning I started to tackle a program that accepts comments from a form and then displays them all on the same page! So far it works great but I’m having trouble taking this program to the next stage. Comment Deletion.

So, the way I got the comments to output is by putting each comment object in an array, and then concatenating each comment String together. By putting each comment into a static variable.

AllComments.addComment(comments[count].toString());

And then in my JSP page I have something like this

<%=AllComments.getAllComments() %>

So it works great. A new comment comes in, it’s concatenated, and then all the comments are printed out as one formatted String.

The problem with this is even thought it works, by putting the comments all together I can never do anything to them again. So this makes it impossible to do my next step which would be to have a link next to each comment with the option to delete.

So in order to do that I’m thinking that I need to display the comments as a loop on my JSP page and show each comment as an individual String. And then if anyone clicks delete I can remove that comment from the array!

So far this is what I was doing trying in my JSP page

<%
    for (int i = 0; i < UserBean.getCommentCount(); i++)
    {
        %>
            <%=comments[i].toString() %>
        <%
    }
%>

However this isn’t working b/c the scope of the comments reference variable is only within the protected doPut method and it’s package. So what should i do to get my comments to output within the loop one comment at a time! You can view my entire servlet class below. Thank you for taking the time to read this.

if (!request.getParameter("fullName").equals("") && !request.getParameter("comment").equals(""))
{
    UserBean[] comments = new UserBean[10];
    int count = UserBean.getCommentCount();

    comments[count] = new UserBean();
    comments[count].setFullName(request.getParameter("fullName"));
    comments[count].setDate(String.valueOf(new Date()));
    comments[count].setComment(request.getParameter("comment"));
    AllComments.addComment(comments[count].toString());

    UserBean.incrementCommentCount();
}
  • 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-09T11:36:37+00:00Added an answer on June 9, 2026 at 11:36 am

    You could set comments to request or sessions attributes, depends on whether you redirects to JSP or not. (If redirect then session, cause request attributes will be empty). And then get comments on JSP page from session or request.

    Inside doPut method after filling comments

    request.setAttribute("comments",comments);
    request.getSession().setAttribute("comments",comments);
    

    And on JSP page you will need to add to the top

    <% UserBean[] comments = (UserBean[]) request.getAttribute("comments"); %>
    <% UserBean[] comments = (UserBean[]) session.getAttribute("comments"); %>
    

    Hope it helps.

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

Sidebar

Related Questions

First off, thanks to whomever is reading this. I have a very strange problem
First off thank you in advance for taking time to help me with this,
First off, let me thank you if you're taking the time to look at
First off, thanks in advance for your help. This issue is driving me nuts.
First off I use this code to make the navigation bar always stay fixed;
This question is a spin-off from this one . Some history: when I first
first off thank you for the pointer that something.endsWith doesn't do what i was
In flex/lex/bison/yacc (all of which I just started reading about), you can set $$
First off thanks to all the users who have made my android developing adventure
First off I would like to say that I think that my question may

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.