Choose Your Language

Tuesday, 18 June 2013

Embedding javascript in servlet to open a jsp page in new window

MyServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            PrintWriter out = response.getWriter();
            out.println("<script>function openWin(){myWindow=window.open('mypage.jsp','mypage.jsp','width=200,height=100'); myWindow.focus();}</script>");
            }
           
}



index.html
<html>
          <body>
                     <form method="post"  action="/MyServlet ">
                                    <input type="submit"  value="click me">
                     </form>
          </body>
</html>

1 comment: