0

I am trying to communicate with a servlet and jsp via an applet. When the button in the applet is clicked request is fired to the servlet and then i try to forward from that servlet to a jsp page. Though the request is made successfully to the servlet's doGet method,i neither see a servlet page in the browser nor a jsp page. why is that ? what am i missing ?

applet button click code :

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    System.out.println("pressed the button !");
    try {
          URLConnection connection = new URL("http://localhost:8084/poll/servlet_1").openConnection();
          connection.setRequestProperty("Accept-Charset", "UTF-8");
          InputStream response  = connection.getInputStream();
          connection.connect();
    }catch(Exception exc) {
        exc.printStackTrace();
    }
}

servlet code :

@Override
public void doGet(HttpServletRequest request,HttpServletResponse response) throws 
        ServletException,IOException {
    System.out.println("---inside the doGet method of servlet----");
    PrintWriter writer = response.getWriter();
    response.setContentType("text/plain");
    writer.println("You just landed on a servlet from an applet !");
    RequestDispatcher rd = request.getRequestDispatcher("jsp_1.jsp");
    rd.forward(request, response);
}

What i see in the server log is the message : ---inside the doGet method of servlet----

when i fire the event the first statement inside the doGet method gets printed but the request is not forwarded to the jsp page. why is that ?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • There is one possibility that jsp_1.jsp is not relative to your current request. If you don't give "absolute path" of the JSP, server tries to lookup for jsp_1.jsp relative to current request URL path on request.requestDispatcher. – kosa Jul 06 '12 at 19:07

1 Answers1

0

If I am getting you correctly you need to Redirect from an applet to servlet and then forward JSP page?

after your servlet response
.....redirect to jsp from applet.

 AppletContext appletContext = getAppletContext();
 appletContext.showDocument(new URL(getDocumentBase(), "yourJsp.jsp")); 
Suave Nti
  • 3,721
  • 11
  • 54
  • 78