Passing value from servlet to html

41,697

Solution 1

You can pass the data from servlet to JSP (not HTML) using request forward and by setting data as attribute in request and then on JSP you can render those data to generate HTML


See

Solution 2

In your Servlet, set data as attribute in request:

RequestDispatcher dispatcher = request.getRequestDispatcher("yourJspPage.jsp");
request.setAttribute("Name", "Temp"); // set your String value in the attribute
dispatcher.forward( request, response );

In your jsp page, access the request attribute like this:

<table>
    <tr>
        <td><%=request.getAttribute("Name")%></td>
    </tr>
</table>

Hope this helps!

Share:
41,697
London guy
Author by

London guy

Passionate about Machine Learning, Analytics, Information Extraction/Retrieval and Search.

Updated on July 05, 2022

Comments

  • London guy
    London guy almost 2 years

    I have a servlet that processes some content from the web and generates a String value. I need to display this String value in a html page within a table tag.

    How do I pass this string value from servlet using the setAttribute method and getrequestdispatcher method?

    Thanks Abhishek S