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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:38:50+00:00 2026-06-11T07:38:50+00:00

I need to display the data from a servlet in a jsp page. At

  • 0

I need to display the data from a servlet in a jsp page.
At the moment I have this:

SERVLET:

Object data = text;
request.setAttribute("data", data);
request.getRequestDispatcher("index.jsp").forward(request, response);

JSP:

<p>result: ${data}</p>

In the JSP there is a simple text box and a send button.
At the moment when I push the send button the response is being overwritten ervery time.

How can I do it that after every search I see the result in a new line?
I want also see the previous searches…

Thanks a lot!

  • 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-11T07:38:51+00:00Added an answer on June 11, 2026 at 7:38 am

    You’ve got a couple of options:

    1. Send over the current value to the server, do the search and append the new result there, and send back the whole string to the JSP in the Request to display it all again. You’ll have to wrap the value in an <input> tag, possibly <input type="hidden"> if you still want to show data in a <p> and not as an input field.

      JSP:

      <input type="hidden" name="oldData" value="${data}"/>
      <p>result: ${data}</p>
      

      Servlet:

      Object newData = text;
      Object oldData = request.getParameter("oldData");
      request.setAttribute("data", oldData + "<br/>" + newData);
      request.getRequestDispatcher("index.jsp").forward(request, response);
      
    2. Store all values of data in the session scope, and just append to it from your servlet. The JSP would have to output the value from the session scope instead of the request. In this example values are stored in a unique concatenated String. It woukld probably be nicer to store each value of data in a data structure, such as a List, and just iterate over it in the JSP so the separator remains in the view.

      JSP:

      <c:if test="${not empty sessionScope.data}">
          <p>result: ${sessionScope.data}</p>
      </c:if>
      

      Servlet:

      Object newData = text;
      Object oldData = request.getSession().getAttribute("data");
      request.getSession().setAttribute("data", oldData + "<br/>" + newData);
      request.getRequestDispatcher("index.jsp").forward(request, response);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a situation where we need to display data from a database in
I need display data from a web page in a ListView, for example if
I need to display a real time data from MS SQL 2005. I saw
I need to be able to display data that I have in 15 minute
I have 1000 rows of data but need to only display 100 rows at
I need to create interface MultiLingual, that allows to display object's data in different
I need to display data from a database in a html table. I am
Basically I have a table that is being used to display data from an
I need to display a data from a database which contains strings like &amp;
I need to display some external data from php file to .tpl file. For

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.