-1

I am try to save a Text as Attribute in servlet and forward it to a HTML page.Then need to show it in Html page body. Help me to send the data as response to HTML.then help to show the value in HTML page. In JSP is working fine.but i need to send the response to html page and show it.

Here i am using Request dispatcher for send the request and response to html page.
but i am not clear with how to display it in html.Help me tp solve. 

 thanks

 //NewServlet.java

 public class NewServlet extends HttpServlet {
 protected void processRequest(HttpServletRequest request,HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    request.setAttribute("Cricket", "Sachin");
    RequestDispatcher rd = request.getRequestDispatcher("index.html");
    rd.forward(request, response);
}

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    processRequest(request, response);
   }
 }

//index.html

enter image description here

Sriram S
  • 533
  • 3
  • 26

1 Answers1

-1

If the file index.html is on another server, you don't need to use the request's attributes because you need to do another request, and the servlet API doesn't provide what you need.

You can obtain the file's content by using a HttpURLConnection for instance. Then you need to process that content to insert your data, then write the result to the servet response.

Maurice Perry
  • 9,261
  • 2
  • 12
  • 24