0

我正在尝试与 aservletjsp通过小程序进行通信。当单击小程序中的按钮时,请求被触发到 servlet,然后我尝试从该 servlet 转发到 jsp 页面。尽管对 servlet 方法的请求成功,但doGet我在浏览器中既没有看到 servlet 页面,也没有看到 jsp 页面。这是为什么 ?我错过了什么?

小程序按钮点击代码:

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();
    }
}

小服务程序代码:

@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);
}

我在服务器日志中看到的是消息:---inside the doGet method of servlet----

当我触发事件时,方法中的第一条语句doGet被打印,但请求不会转发到jsp页面。这是为什么 ?

4

1 回答 1

0

如果我让您正确,您需要从小程序重定向到 servlet,然后转发 JSP 页面?

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

 AppletContext appletContext = getAppletContext();
 appletContext.showDocument(new URL(getDocumentBase(), "yourJsp.jsp")); 
于 2012-07-06T18:38:56.113 回答