2012-07-06 6 views
0

애플릿을 통해 servletjsp과 통신하려고합니다. 애플릿의 버튼을 클릭하면 요청이 서블릿에 발생하고 그 서블릿에서 JSP 페이지로 전달하려고 시도합니다. 요청이 서블릿의 doGet 메소드에 성공적으로 수행되었지만 브라우저의 서블릿 페이지 나 JSP 페이지가 표시되지 않습니다. 그게 왜? 내가 뭘 놓치고 있니?애플릿에서 fire 단추를 클릭하면 왜 새로운 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(); 
    } 
} 

서블릿 코드 : ---inside the doGet method of servlet----

난을 : 내가 서버 로그에 표시되는 내용

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

는 메시지입니다 이벤트를 첫 번째 역에서 시작하십시오. doGet 메서드 내부의 내용이 인쇄되지만 요청은 jsp 페이지로 전달되지 않습니다. 그게 왜?

+0

jsp_1.jsp가 현재 요청에 비례하지 않을 가능성이 있습니다. JSP의 "절대 경로"를 제공하지 않으면 서버는 request.requestDispatcher의 현재 요청 URL 경로를 기준으로 jsp_1.jsp를 조회하려고 시도합니다. – kosa

답변

0

제대로 얻으려면 애플릿에서 서블릿으로 리디렉션 한 다음 JSP 페이지를 전달해야합니까?

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

AppletContext appletContext = getAppletContext(); 
appletContext.showDocument(new URL(getDocumentBase(), "yourJsp.jsp")); 
관련 문제