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 ?