Issue
I'm looking for a way to send a redirection with my servlet from my first page to a second page adding into the second page a script tag made inside this servlet.
For example:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("Received a get request");
response.getWriter().append("<script>alert(\"I'm here!\")</script>");
response.sendRedirect("testRedirect.html");
}
This code doesn't work. How can I fix it? Thanks!
Solution
Thank for your answers I solved with this code:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("received a get message");
PrintWriter out = response.getWriter();
out.println("<script>alert(\"I'm here\");</script>");
request.getRequestDispatcher("testRedirect.html").include(request, response);
out.close();
}
Answered By - Davide
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.